PHWinfo banniere

Titres
ACCUEIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.info.servers.unix > mod_rewrite problem
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.info.servers.unix Web servers for UNIX platforms.

mod_rewrite problem

Réponse
 
LinkBack Outils de la discussion
Vieux 02/02/06, 22h45   #1
Manfred Kooistra
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.)

  Réponse avec citation
Vieux 03/02/06, 17h24   #2
Andreas Prilop
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.

  Réponse avec citation
Vieux 03/02/06, 19h49   #3
Manfred Kooistra
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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?

  Réponse avec citation
Vieux 05/02/06, 19h11   #4
Manfred Kooistra
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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".

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 21h44.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2009
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10171 seconds with 12 queries