How do I make my rule match an exact value of a cookie? I've tried:
RewriteCond %{HTTP_COOKIE} ^its=me$ [NC]
RewriteCond %{HTTP_COOKIE} its=^me$ [NC]
RewriteCond %{HTTP_COOKIE} its="me" [NC]
RewriteCond %{HTTP_COOKIE} its=me [NC]
The last almost works, but matches when extra text is at the end of the value, like "me2". The condition should be true only if the its
cookie has an exact value of me
, with nothing more before or after.
These values should not match:
- you
- me2
- [empty string]
- [cookie is not set at all]
There could be of course several cookies, and they can be URL escaped, making comparisons tricky.
Something like this ought to work in most cases:
If you need to unescape the cookie you can add a rewritemap for that:
RewriteMap unescape int:unescape
It doesn't need to be more complicated than
Note that if the cookie value contains special (not URL-safe) characters, Krist van Besien's solution probably works best.
From the online docs:
Does this work?
RewriteCond %{HTTP_COOKIE} =its=me [NC]