SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    yet another .htaccess question

    Hi all.

    I want to have two languages on my website: english and german.

    By doing this I am trying to pass two PHP variables between webpages: $page, and $lang.

    I have been using this rewrite rule:

    RewriteRule ^/(en|de)/([A-Za-z0-9]+)$ index.php?lang=$1&page=$2

    but I cannot get it to work. A typical 'a href' link should then be something like "a href="/en/news" or "a href="../en/news" in this case, right?

    If I simply type in the variables in the URL like this:

    ?lang=de&page=news

    it works fine and I can change the language to english by replacing "de" with "en" successfully and change the page variable easily.

    However, I want a clean URL and would like to have:

    example.com/de/news

    instead where in this case "de" represents the ?lang value and "news" represents the ?page value.

    If I put the .htaccess folder in the root folder, then I shouldn't have to worry about subdirectories and the hierarchy of folders, correct?

    PHP code:

    <?php
    if (!isset($_GET['page'])) {
    $_GET['page'] = 'home';
    }
    $page = $_GET['page'];
    ?>
    <?php
    if (!isset($_GET['lang'])) {
    $_GET['lang'] = 'en';
    }
    $lang = $_GET['lang'];
    ?>

    My current folder directory is something like root->content->de->news.php

    Sorry for the long post but I appreciate any help.

  2. #2
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind I got it working now.

    I renamed my de.php and en.php files to deutsch.php and english.php. I had the $lang value the same as the .php files, which was why it wasn't working. So in the future make sure your variables are not the same name as your .php files when rewriting.
    A newbie mistake.

  3. #3
    SitePoint Member admedia's Avatar
    Join Date
    May 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by illphil View Post
    Nevermind I got it working now.

    I renamed my de.php and en.php files to deutsch.php and english.php. I had the $lang value the same as the .php files, which was why it wasn't working. So in the future make sure your variables are not the same name as your .php files when rewriting.
    A newbie mistake.
    If I have a file named company.php in my localhost and browse to http://localhost/company/ the company.php takes precedence and is displayed. This is not true on my server though. I am thinking there is a setting in the httpd.conf to adjust this setting? It's annoying and gets in the way of my .htaccess rewriting. I should get a page not found IMO if I did not correctly include the file extension in my URL.

    Can anyone tell me where to change this setting?

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Look for MultiViews then change it's setting to Options -MultiViews.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •