|
|
|
|
||||||
| comp.info.servers.unix Web servers for UNIX platforms. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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? All this is happening on Apache 1.3.33 (And yes, I know that I can direct visitors to different files using AddLanguage etc., but I want to direct them to subdirectories.) |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2 Feb 2006, Manfred Kooistra wrote:
> RewriteCond %{HTTP_ACCEPT_LANGUAGE} ^en [NC] > RewriteRule ^/ http://www.domain.com/en/ [L,R=301] > RewriteRule ^/ http://www.domain.com/no/ [L,R=301] "no" is a bad choice, because it would suggest "Norwegian". > Does RewriteCond not understand the > HTTP_ACCEPT_LANGUAGE variable, So it is. http://httpd.apache.org/docs/1.3/mod...ml#RewriteCond > or did I make some mistake? Yes, you tried to solve a problem with mod_rewrite where you should use other tools. > (And yes, I know that I can direct visitors to different files using > AddLanguage etc., Fine, then. Problem solved. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Andreas Prilop schrieb: > "no" is a bad choice, because it would suggest "Norwegian". It is in fact supposed to mean "Norwegian" - that is the default language in my example. > > Does RewriteCond not understand the > > HTTP_ACCEPT_LANGUAGE variable, > > or did I make some mistake? > > Yes, you tried to solve a problem with mod_rewrite where you > should use other tools. Well, there are quite a few examples on the web, where people utilize HTTP_ACCEPT_LANGUAGE in exact the same way as I tried to do. Obviously they were all mistaken. Strange. Anyway, how can I get a redirect into a subdirectory based on HTTP_ACCEPT_LANGUAGE? AddLanguage does not do this (it only adds an extension), and I cannot limit it to the current directory (because it works on all subdirectories as well). So how to do it? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Andreas, this is my solution to the problem (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] Yes, 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". |
|
![]() |
| Outils de la discussion | |
|
|