This is a discussion on mod_rewrite problem within the Apache Web Server forums, part of the Web Server and Related Forums category; I am trying to redirect visitors of my home directory to different subdirectories, depending on the accept language header sent ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am trying to redirect visitors of my home directory to different
subdirectories, depending on the accept language header sent by the browser. For this I wrote a .htaccess file with the following content: RewriteEngine On RewriteCond %{HTTP_ACCEPT_LANGUAGE} ^de [NC] RewriteRule ^/ http://www.domain.com/de/ [L,R=301] RewriteCond %{HTTP_ACCEPT_LANGUAGE} ^en [NC] RewriteRule ^/ http://www.domain.com/en/ [L,R=301] RewriteRule ^/ http://www.domain.com/no/ [L,R=301] But when I go to www.domain.com (with my browser set to "de" or "en" - I checked that this is indeed transferred), I always end up in the .../no directory. Does RewriteCond not understand the HTTP_ACCEPT_LANGUAGE variable, or did I make some mistake? (And yes, I know that I can direct visitors to different files using AddLanguage etc., but I want to direct them to subdirectories.) |
|
|||
|
Manfred Kooistra wrote:
> Does RewriteCond not understand the > HTTP_ACCEPT_LANGUAGE variable, or did I make some mistake? Hard to remember but I think I also tried something like this in the past which did not work in per-dir and per-server context (even if you perform a subrequest lookup for the variable). Only HTTP_ACCEPT was accessible, AFAICR. -- Robert |
|
|||
|
Thank you, Robert. Yes, you are right. I found a solution (example for
two languages): RewriteEngine On RewriteBase / RewriteCond %{HTTP:Accept-Language} ^.*de.*$ [NC] RewriteRule ^(index\.php)?$ http://www.domain.com/de/ [L,R=301] RewriteCond %{HTTP:Accept-Language} ^.*en.*$ [NC] RewriteRule ^(index\.php)?$ http://www.domain.com/en/ [L,R=301] RewriteRule ^(index\.php)?$ http://www.domain.com/de/ [L,R=301] The regular expression will be refined not to serve "de" to someone prefering English but knowing German, not to someone not wanting German and stating "de; q=0". |
|
|||
|
Thank you, Robert. Yes, you are right. I found a solution (example for
two languages): RewriteEngine On RewriteBase / RewriteCond %{HTTP:Accept-Language} ^.*de.*$ [NC] RewriteRule ^(index\.php)?$ http://www.domain.com/de/ [L,R=301] RewriteCond %{HTTP:Accept-Language} ^.*en.*$ [NC] RewriteRule ^(index\.php)?$ http://www.domain.com/en/ [L,R=301] RewriteRule ^(index\.php)?$ http://www.domain.com/de/ [L,R=301] The regular expression will be refined not to serve "de" to someone prefering English but knowing German, nor to someone not wanting German and stating "de; q=0". |