0

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'">
    ...
</If>
2

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 | |
1

We can also use the below code

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

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.