[英]HTTP_COOKIE RewriteCond Failing
I have the following Rewrite
code in my Apache config file but I can't get it to recognize when the cookie is present. 我的Apache配置文件中包含以下
Rewrite
代码,但是当cookie存在时我无法识别它。 I've looked a bunch of answers on here but can't seem to find one that fixes whatever issue I'm running into. 我在这里已经找到了很多答案,但似乎找不到能解决我遇到的任何问题的答案。
RewriteEngine on
RewriteCond %{HTTP_COOKIE} ^returnvisitor$ [NC]
RewriteRule .? - [S=3]
RewriteRule /index.html /new_visitor.html
RewriteRule .* - [CO=returnvisitor:yes:.127.0.0.1:1440:/:true:true]
RewriteRule .? - [S=1]
RewriteRule /index.html /returning_visitor.html
Update 1: 更新1:
I've modified the code as follows and made some progress, but still doesn't act as it should. 我对代码进行了如下修改,并取得了一些进展,但仍然无法正常工作。
RewriteEngine on
RewriteCond %{HTTP_COOKIE} returnvisitor=yes [NC]
RewriteRule .? - [S=3]
RewriteRule /index.html /new_visitor.html [R]
RewriteRule .* - [CO=returnvisitor:yes:.127.0.0.1:1440:/:true:true]
RewriteRule .? - [S=1]
RewriteRule /index.html /returning_visitor.html [R,L]
The original code would redirect the homepage (ie the default page being index.html
) however, now I have to manual request index.html
in the url for the redirect to trigger, but at least this time on the second request of index.html
I'm redirected to returning_visitor.html
. 原始代码将重定向主页(即默认页面为
index.html
),但是,现在我必须在URL中手动请求index.html
才能触发重定向,但至少这次是在index.html
的第二个请求上我被重定向到returning_visitor.html
。
I need the redirects to occur when accessing the hompage via example.com
for the first time the visitor is sent to new_visitor.html
and subsequent visits are redirected to returning_visitor.html
. 我需要在首次将访问者发送到
new_visitor.html
并将其后续访问重定向到returning_visitor.html
时,通过example.com
访问new_visitor.html
进行重定向。 With out having to manual enter example.com/index.html
. 无需手动输入
example.com/index.html
。
You can use : 您可以使用 :
RewriteEngine on
#First visit
# if the cookie is not set
RewriteCond %{HTTP_COOKIE} !returnvisitor=yes$ [NC]
# serve "/new_visitor.html"
RewriteRule /index.html /new_visitor.html [R,L]
#second visit
#set the cookie "returnvisitor" on any uri
RewriteRule .* - [CO=returnvisitor:yes:.127.0.0.1:1440:/:true:true]
#check to see that the cookie is set
RewriteCond %{HTTP_COOKIE} returnvisitor=yes$ [NC]
#if so, redirect the index.html to "/returning_visitor.html"
RewriteRule /index.html /returning_visitor.html [R,L]
Let me know how it works for you. 让我知道它如何为您服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.