This simple rule in .htaccess
handles languages at my website:
RewriteRule "^(de|it|es|fr|en-us)(?:|/(.*))$" "$2?lang=$1" [NC,QSA]
It works fine unless I miss slash at the end of URL. Than it changes URL in browser's address bar which is not what I want.
To make myself more clear look at examples bellow.
http://mydomain/en-us/projects/
keeps that URL in address bar and calls http://mydomain/projects?lang=en-us
which is OK (+generates REDIRECT_STATUS=200
).
http://mydomain/en-us/projects
(notice missing slash at the end) calls same URL but makes change in address bar (it doesn't generate REDIRECT_STATUS
).
As I have almost zero experience with Apache stuff must ask you how to rewrite any of URLs like
http://mydomain/[lang_id]
http://mydomain/[lang_id]/more/dirs/here/
http://mydomain/[lang_id]/test.php
to
http://mydomain?lang=[lang_id]
http://mydomain/more/dirs/here?lang=[lang_id]
http://mydomain/test.php?lang=[lang_id]