I have some difficulties with the mod_rewrite rules for language folders. I want to rewrite any request on: www.example.com/lang/* to: www.example.com/*
I add rule
RewriteRule ^lang/(.*)$ \/$1
As I use several language I'd like to save in enviroment wich exactly language in URL is typed at first opening of site.
Futher I use rule
SetEnvIf Referer "www.example.com/lang1/" LANG=1
SetEnvIf Referer "www.example.com/lang2/" LANG=2
So I got language to show on site
However I could not get this enviroment when typing address www.example.com/lang1/ in browser
As this is an internal rewrite (the new path is used instead of the old one), there is no communication with the client and therefore no new Referer set.
But using the referer is always unreliable. Consider modifying the RewriteRule so that it contains the original request URI in the query string.
This would be
RewriteRule ^lang/(.*)$ \/$1&uri=%{REQUEST_URI}
if your requests contain a query string, and
RewriteRule ^lang/(.*)$ \/$1?uri=%{REQUEST_URI}
if not. The original URI would then be contained in the variable $_GET['uri']
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.