mod_rewrite problem

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 ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-02-2006
Manfred Kooistra
 
Posts: n/a
Default mod_rewrite problem

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.)

  #2 (permalink)  
Old 02-05-2006
Robert Ionescu
 
Posts: n/a
Default Re: mod_rewrite problem

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
  #3 (permalink)  
Old 02-05-2006
Manfred Kooistra
 
Posts: n/a
Default Re: mod_rewrite problem

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".

  #4 (permalink)  
Old 02-05-2006
Manfred Kooistra
 
Posts: n/a
Default Re: mod_rewrite problem

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".

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:15 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0