SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    410
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SEO links - Multi Language

    Hi Chaps...

    Ive just finished a site using SEO links, however now, onto the next one, i need to do multi language. The database uses the lang session value to pull down data eg products_en, products_de, products_fr etc etc.

    In my pages i have the following code that refreshes the actual page and applies a ?lang=en value

    PHP Code:
    $_SESSION['lang'] = $lang = (isset($_GET['lang']) ?
     
    mysql_real_escape_string(trim($_GET['lang'])) : (isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en')); if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""

    so.....how would i adapt the above code from producing:
    website.com/product.php?lang=en

    to something that can pass the session value to give something like:
    website.com/en/product


    ...thanks in advance

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean mod-rewrite?
    Code:
    RewriteEngine on 
    RewriteRule (.*?)_(.*?)$ index.php?$1=$2
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    410
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hum....i suppose that could work...but im a bit unsure!

    Would i use somthing like this....or keep the language variable separately?

    rewriterule ^wines/([^&]+)/([A-Z0-9-&'!?\(\)\ ]+) $ /wines.php?langid=$1&winetitle=$3 [NC,L]

  4. #4
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use following concept instead:
    PHP Code:
    if(check_in_cookie){
    //get lang from cookie
    }elsif(check_in_session){
    //get lang from session
    }else{
    //get lang from db

    and use this lang value wherever necessary.

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    410
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers

    this is where my stupidity is exposed!....

    How can i set the language session via the buttons without adding the old ?lang=blah at the end?

    many thanks

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    410
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hum........is there anyone out there that can help me with this?

    thanks in advance

  7. #7
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple:
    Make lang editable from backend and while saving you can too save in SESSION & COOKIE.

  8. #8
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    language session is very seo unfriendly
    wonder why do you want such thing

  9. #9
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    language session is very seo unfriendly
    wonder why do you want such thing
    yes why don't you use subdomains like en.mysite.com or using string as separators like mysite.com/en

  10. #10
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    410
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, thats what i was thinking with my initial post...so really ive got to specific questions...

    For all the url's, would it be best to do something like...

    Code:
    website.com/<?php echo "$lang"?>/product
    (and change the htaccess file accordingly)

    Based on the code that ive been using (in the first post), how would i change the following button code, so that it refreshes the same page that the visitor is on, with the relevant language content (from the database with product_en, product_it etc etc) without adding the old ?lang=it at the end of the url?

    Code:
    <?php
    
    if ($_SERVER['QUERY_STRING'])
           {
                 
                  echo "<a href=\"?{$_SERVER['QUERY_STRING']}&lang=en\">ENGLISH</a>";
           }
    else
           {
                 
                  echo "<a href=\"?lang=en\">ENGLISH</a>";
           }
    
    ?>
     | <?php
    
    if ($_SERVER['QUERY_STRING'])
           {
                 
                  echo "<a href=\"?{$_SERVER['QUERY_STRING']}&lang=it\">ITALIANO</a>";
           }
    else
           {
                 
                  echo "<a href=\"?lang=it\">ITALIANO</a>";
           }
    
    ?>
    thanks, b


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
  •