Forum Moderators: phranque
I run a multilingual site. The language system is totaly transparent at the moment so the URL's are exactly the same for all languages. The language used is controlled by PHP sessions. The problem with this design is that search enginges only spider the main language and im trying to solve that. I don't want to use country specific top domains for each language or subdomains since its a site where people from different countries interact with eachother.
So what I want is to use mod_rewrite in some way so the url looks like I have a directory for each language. If you for example are using german language the url will be www.sitename.com/DE/index.php and so on.
One idea I have is to translate the url to "index.php?lang=DE" but the site got hundreds of pages and more gets added often so having one rewrite rule for every page is not really doable and I would like to avoid having to always send a GET-value (lang) to all pages if possible. So I guess I have three questions:
- Would it be possible to somehow set a apache environmental variable from PHP that mod_rewrite could use to make the url look like it uses a subdirectory for each language?
- Is it possible to write a rule to always translate a url like www.sitename.com/DE/index.php to index.php?lang=DE for all the pages and that works even if there are other GET values sent to the page (ie. index.php?f=2&d=1&lang=DE.
- Am I totaly out in the blue and there are other really smart solutions to my problem? :)
Thanks alot in advance!
kindest regards
Tomas
Welcome to WebmasterWorld!
> Is it possible to write a rule to always translate a url like www.sitename.com/DE/index.php to index.php?lang=DE for all the pages and that works even if there are other GET values sent to the page (ie. index.php?f=2&d=1&lang=DE.
RewriteCond %{QUERY_STRING} !lang=[A-Z]{2}
RewriteRule ^([A-Z]{2}/index\.php$ /index.php?lang=$1 [QSA]
The code will not rewrite if the lang= parameter is already present, so this prevents a possible infinite-loop problem.
Jim
If its not possible to have one rule for all files is it how much of a cpu hog is mapping a textfile with all the filenames to mod_rewrite?
Thanks in advance!