Mobile app version of vmapp.org
Login or Join
Nickens628

: Apache .htaccess: Is it possible to write an if condition for a cookie value check? I want to write an if condition in an .htaccess file to check whether a cookie value is set. Example

@Nickens628

Posted in: #Apache #Cookie #Htaccess #ModRewrite #UrlRewriting

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>

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Nickens628

2 Comments

Sorted by latest first Latest Oldest Best

 

@Vandalay111

We can also the below code

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


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

10% popularity Vote Up Vote Down


 

@Gonzalez347

This seems to do the trick for me:

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


The s* part is probably overkill.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme