htaccess比较cookie值,如果评估返回true/false,则重定向

编程入门 行业动态 更新时间:2024-10-09 06:26:20
本文介绍了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 .* www.google [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 ^ www.google [NC,L]

更多推荐

htaccess比较cookie值,如果评估返回true/false,则重定向

本文发布于:2023-11-01 11:10:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549177.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   cookie   htaccess   false   true

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!