mod_rewrite 中的规则异常

发布于 2024-12-27 14:53:11 字数 644 浏览 2 评论 0原文

我创建了每个新用户在访问时都会重定向到的页面,它设置了一个 cookie,允许访问我网站的其余部分。我想为某些网站及其机器人添加此规则的例外:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} http://www.site1.com [NC,OR]
RewriteCond %{HTTP_REFERER} http://www.site2.net [NC,OR]
RewriteCond %{HTTP_USER_AGENT} bot1 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} bot2 [NC]
RewriteRule .? - [S=1]
RewriteCond %{HTTP_COOKIE} !yes=1 [NC]
RewriteRule !^(script1.php|script2.php)$ script2.php [L]
</IfModule>

如您所见,如果 cookie 不存在或 !=1,则每个用户都会重定向到 script2.php。

我写了一些例外,但有时有效,有时无效。

我在某个地方犯了错误,但我没有看到它。

你能帮我解决这个问题吗?谢谢您抽出时间。

I have created page that every new user is redirected to upon visit, it sets a cookie that allows access to the rest of my site. I want to add exception to this rule for some sites and their bots:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} http://www.site1.com [NC,OR]
RewriteCond %{HTTP_REFERER} http://www.site2.net [NC,OR]
RewriteCond %{HTTP_USER_AGENT} bot1 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} bot2 [NC]
RewriteRule .? - [S=1]
RewriteCond %{HTTP_COOKIE} !yes=1 [NC]
RewriteRule !^(script1.php|script2.php)$ script2.php [L]
</IfModule>

As you can see, if the cookie doesn't exist or !=1 every user is redirected to script2.php.

I wrote some exceptions, but sometimes it works, and sometimes it doesn't.

I've made an error somewhere, but i don't see it.

Can you help me with this? Thank you for you time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轻拂→两袖风尘 2025-01-03 14:53:11

我宁愿使用 [L] 而不是 [S=1]

其次,我会对 script2.php 进行外部重定向,因此它不会被缓存(不正确)。因此,在最后一条规则中使用 [R,L] 而不是仅使用 [L]

I'd rather use [L] instead of [S=1].

Secondly, I would do a external redirect to script2.php, so it's not cached (incorrectly). So use [R,L] instead of just [L] on your last rule.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文