htaccess compare cookie value and redirect if evaluation returns true/false

Replace required_value with the value that needs to be matched.

RewriteEngine On
RewriteCond %{HTTP_COOKIE} !cookie_name=required_value;? [NC]
RewriteRule ^ http://www.google.com [R=301,L]

;? makes sure that the match happens both when there are multiple cookie value pairs or when cookie_name is the only cookie set. This also prevents from matching on a cookie value like off when a match on only of (a substring) is required.


You can use this code that checks for specific value in the cookie:

RewriteEngine On

RewriteCond %{HTTP_COOKIE} !cookie_name=specific_value [NC]
RewriteRule ^ http://www.google.com [NC,L,R=302]

You're close. The cookie string needs a =:

RewriteEngine On
RewriteCond %{HTTP_COOKIE} !cookie_name=specific_value; [NC]
RewriteRule ^ http://www.google.com [NC,L]