SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot eeight's Avatar
    Join Date
    Oct 2006
    Location
    New York City
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile PHP Language Switch and HTACCESS

    I'm making a bilingual website and have this link on each page:
    PHP Code:
    echo "<a href=\"".$_SERVER['PHP_SELF']."/?lang=ru\">Switch to Russian</a>"
    As you can see, it simply adds a $_GET variable to the end of the current URL. The current page then picks up that variable and switches to the appropriate language.

    Additionally, I have the following mod_rewrite:
    Code:
    RewriteEngine On
    
    Options -Indexes
    
    RewriteCond &#37;{http_host} !^www\.blah\.com$ [nc]
    RewriteRule ^(.*)$ http://www.blah.com/$1 [r=301,nc]
    
    RewriteRule ^([A-Za-z0-9-]+)$ /$1/ [R]
    RewriteRule ^([A-Za-z0-9-]+)/$ /$1.php
    
    RewriteRule ^articles/([A-Za-z0-9-]+)$ articles/$1/ [R]
    RewriteRule ^articles/([A-Za-z0-9-]+)/$ /article.php?id=$1
    The article redirect (/articles/1/ to article.php?id=1) works fine. However, the language switch link doesn't work on the article page. The above PHP would result in a link to: /articles/1/?lang=ru. Nothing happens when I click the language switch on an article page.

    Without the mod_rewrite, I know linking to "article.php?id=1&lang=ru" would work, but how do I do it with the rewrite?

    Thanks for any help.

  2. #2
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't use .htaccess (or the query string) for i18n. Use PHP's __() or some similar function.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  3. #3
    SitePoint Zealot eeight's Avatar
    Join Date
    Oct 2006
    Location
    New York City
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the response, AlienDev. I googled "i18n in php" and found this tutorial, if anyone else is interested:

    http://php-flp.sourceforge.net/getti...ed_english.htm

    In this case, however, since the site is already setup and this is the only thing nagging me, I would still be thankful if anyone can help me with the .htaccess fix.


Tags for this Thread

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
  •