I want to write an if condition in an .htaccess file to check whether a cookie value is set. Example code:

<If "%{HTTP_COOKIE} == 'cookiename and value'">

This seems to do the trick for me:

<If "%{HTTP_COOKIE} =~ /(^|; )cookie-name\s*=\s*some-val(;|$)/>

The \s* part is probably overkill.

| improve this answer | |

We can also use the below code

<If "%{HTTP_COOKIE} =~ /tenant=666/">
        SetEnv lang4 777
        Header add Set-Cookie "logged=%{lang4}e;"

Where tenant is the cookie-name and 777 is cookie-value

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.