1

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?

1 Answer 1

4

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.

2
  • 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, 2011 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, 2011 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.