redirect depending on cookies

Oh, the strange things mod_rewrite does!

redirect depending on cookies

Postby forearrow » Wed May 09, 2007 10:45 pm

Hi, I have a question I suppose will be simple for most of you, however, it's a tough one for me. So I'd really be grateful if you could give me a hand

There is a cookie named 'lang' to remember user language preference,

When lang=en, apache must append '&lang=en' to the requested url
When lang=tw, apache must append '&lang=tw' to the requested url
......

Is it possible?
forearrow
 
Posts: 11
Joined: Fri Apr 27, 2007 10:37 pm

Postby richardk » Fri May 11, 2007 12:16 pm

Try this in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_COOKIE} ^(.*;\ )?(lang=[^;]+)(;\ .*)?$ [NC]
RewriteRule ^(.*)$ ./$1?%2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby forearrow » Mon May 14, 2007 9:43 pm

really thank you very much
forearrow
 
Posts: 11
Joined: Fri Apr 27, 2007 10:37 pm


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 1 guest

cron