views:

20

answers:

1

In htaccess with mod_rewrite, how can I read the value of a cookie and then add that value to the URI?

For example, if a cookie named "foo" is set with a value of "bar", I need htaccess to redirect to:

example.com/?foo=bar

or any variation of that URL:

example.com/folder/stuff/things/?foo=bar
+1  A: 

I haven't tested, but this probably works (the B flag was purposely omitted):

RewriteCond %{HTTP_COOKIE} (?:^|;\s*)foo=([^;]*)
RewriteRule .* $0?foo=%1 [L,QSA,NS]
Artefacto