Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a cookie on my site and would like to have this cookie in the url (*always), something like this: OR

*(i'm not sure if i would like it ALWAYS, maybe i can exclude some directories i guess i can do this with adding a extra RewriteCond)

But the main problem is my code now results in a loop, below the code i use:

RewriteCond %{HTTP_COOKIE} lang=([^;]+) [NC]
RewriteRule ^(.*)$ /$1?lang=%1 [R,QSA,L]

Now my url results in: etc.

How can i simply add a cookie information to the url only once? and not loop all the time...

share|improve this question

migrated from May 9 '11 at 11:04

This question came from our site for professional and enthusiast programmers.

1 Answer 1

Have your rules like this:

RewriteCond %{QUERY_STRING} !^lang= [NC]
RewriteCond %{HTTP_COOKIE} lang=([^;]+) [NC]
RewriteRule ^(.*)$ /$1?lang=%1 [R,QSA,L]

That way you will not not get infinite loop because of 1st negative condition.

share|improve this answer
thx! yes that solved the looping! Great Only i run Drupal and my other urls are now different: is now i guess because of the last rule: /$1?lang=%1 [R,QSA,L] i will try to find out how to make a better rule now – Anonymous May 8 '11 at 22:23
Glad to know. If you think this answer helped you in anyway pls mark it as accepted so that others can also benefit from this. – anubhava May 8 '11 at 22:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.