transparencia Posted September 1, 2010 Share Posted September 1, 2010 My website is multi-language and using mod_rewrite for clean urls. I have a $lang variable that stores the language code. For example: website.com/index.php?lang=en, which turns to website.com/en I use a $_GET["lang"] to get the language and prepare the links to the other pages, for example a link to page1.php would be page1.php?lang=$_GET["lang"]. What I want to know is if this is the right way to do it or there is a better way. Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted September 1, 2010 Share Posted September 1, 2010 If you are having multiple PHP pages (page1.php / page2.php etc) then yes I would do it this way. However, it's not the best way to do it really. I always design sites so that you have one access point for all page requests. I would do pages as: site.com/en/page1 - which reverts to site.com/en/index.php and you pull the page1 value out and display the relevant file (probaly /pages/html/page1.php etc.) site.com/en/page2 - which reverts to site.com/en/index.php and you pull the page2 value out and display the relevant file (probaly /pages/html/page2.php etc.) All links are then to site.com/en/page3 etc. My last example is based on a site designed using a proper MVC system where you have one access point (logic is sperated from html and there is minimal code duplication). It also uses a clean url / mod_rewite as you want. index.php is the only file that is called frm the address bar and this file then calls the relevant other pages (page1, 2 etc.) EDIT: (in reality it would revert to site.com/index.php - you're unlikely to have folders for each language!) Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted September 1, 2010 Share Posted September 1, 2010 I don't know about right way, but the way I do it is to figure out the user's language (they choose, or use a javascript to find out from the browser), then store their language in a session var that is available to all pages. Then you don't have to worry about appending the var to the URL for every link. Unless of course you want to have language in the URL so that they are different URLs for search engines, etc. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.