htaccess比较cookie值,如果评估返回true/false,则重定向 [英] htaccess compare cookie value and redirect if evaluation returns true/false

查看:40
本文介绍了htaccess比较cookie值,如果评估返回true/false,则重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人在htaccess中提供if-else语句来帮助我.我想要的是htaccess来读取Cookie,并检查其值是否等于定义的值.如果评估结果为false,则应执行重定向并阻止从请求的文件夹进行访问.如果评估返回false,也许所有人都否认会更好.

I would like somebody to help me with an if-else statement in htaccess. What I want is htaccess to read a cookie and check if its value equals a defined value. If it evaluates to false, it should excecute a redirect and prevent from the requested folder to be accessed. Maybe a deny from all would be better if the evaluation returns false.

我知道以下代码检查是否设置了命名的cookie值.如果未设置,它将执行下面的重写规则.但是,如何调整这条线,以便检查它是否等于某个值?

I know that the following code checks if a named cookie value is set. If it is not set, it will execute the rewrite rule below it. But how can I adjust this line so that it checks if it equals a certain value?

RewriteEngine On
RewriteCond %{HTTP_COOKIE} !^.*cookie_name.*$ [NC]
RewriteRule .* http://www.google.com [NC,L]

我想要的,但是采用.htaccess风格:

What I would like, but in .htaccess style:

if ($_COOKIE['cookie_name'] != 'specific_value'){
//rewrite_rule or deny from all.
}

推荐答案

您已经关闭. Cookie字符串需要=:

You're close. The cookie string needs a =:

RewriteEngine On
RewriteCond %{HTTP_COOKIE} !cookie_name=specific_value; [NC]
RewriteRule ^ http://www.google.com [NC,L]

这篇关于htaccess比较cookie值,如果评估返回true/false,则重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆