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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

www.domain.com/?lang=en OR www.domain.com/subscribe/?lang=en

*(I'm not sure if I would like it ALWAYS, maybe I can exclude some directories? I guess I can do this by adding an extra RewriteCond.)

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

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

Now my URL results in:

www.domain.com/?lang=en?lang=en?lang=en?lang=en?lang=en?lang=en?lang=en?lang=en?lang=en?lang=en?lang=en?lang=en ... etc.

How can I simply add cookie information to the URL only once, and not loop all the time?

share|improve this question

migrated from stackoverflow.com May 9 '11 at 11:04

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

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: www.domain.com/subscribe is now www.domain.com/index.php?currency=en&q=subscribe 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

 
discard

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