Apache rewrite rules for cookies

和自甴很熟 提交于 2020-02-03 08:37:05

问题


I have an interesting problem.

I need to implement rewrite rules based on if a cookie is there or not. Thats easy enough, the below rewrite rule will check if the cookie is there and if it is it will not redirect, equally if it is not there it will redirect.

RewriteCond %{HTTP_COOKIE} !^.mycookie.$ [NC]

All good so far. Now what I want to do is, if the cookie is present and the value is a specific value then I want to redirect.

I have tried the following combinations which I thought would work but neither do:

RewriteCond %{HTTP_COOKIE} !^.*mycookie.*$ [NC] 
RewriteCond %{HTTP_COOKIE} mycookie='XX' [NC]

RewriteCond %{HTTP_COOKIE} !^.*mycookie.*$ [NC] [OR]
RewriteCond %{HTTP_COOKIE} mycookie='XX' [NC]

The rules for my rewrite conditions in summary are:

  1. If the cookie is there do not redirect unless the value is XX in which case follow the redirect
  2. If the cookie is not there redirect

Thanks in advance

来源:https://stackoverflow.com/questions/6943968/apache-rewrite-rules-for-cookies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!