mod_rewrite 中的规则异常
我创建了每个新用户在访问时都会重定向到的页面,它设置了一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我宁愿使用
[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.