PHWinfo banniere

ACCUEIL ANNUAIRE ARTICLES COMPARATIF HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Go Back   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.info.servers.unix > mod_rewrite problem
FAQ Members List Search Today's Posts Mark Forums Read
comp.info.servers.unix Web servers for UNIX platforms.

mod_rewrite problem

Reply
 
Thread Tools
Old 02/02/06, 22:45   #1
Manfred Kooistra
Aucun Avatar
 
Posts: n/a
Hébergeur:
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?

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

  Reply With Quote
Old 02/03/06, 17:24   #2
Andreas Prilop
Aucun Avatar
 
Posts: n/a
Hébergeur:
Default Re: mod_rewrite problem

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.

  Reply With Quote
Old 02/03/06, 19:49   #3
Manfred Kooistra
Aucun Avatar
 
Posts: n/a
Hébergeur:
Default Re: mod_rewrite problem


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?

  Reply With Quote
Old 02/05/06, 19:11   #4
Manfred Kooistra
Aucun Avatar
 
Posts: n/a
Hébergeur:
Default Re: mod_rewrite problem

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

  Reply With Quote
Reply


Thread Tools

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 On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT +1. The time now is 22:33.


Powered by vBulletin® ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
PHWinfo is a website Education Without Frontiers
Ad Management by RedTyger
All rights reserved
Page generated in 0.16495 seconds with 8 queries