如何过滤所有包含字符串但不包含子字符串的 Apache URL
我正在尝试过滤所有尝试访问 URL 中包含 path=\
的地址的客户端(使用 .htaccess),但不过滤那些包含 _wpnonce=1234567890
的 URL >。
逻辑是:阻止除那些也拥有 _wpnonce 的人之外的所有人 参数。
阻塞,不测试它是否包含子字符串,看起来像这样:
RewriteCond %{QUERY_STRING} (menu|mod|path|tag)\=\.?/? [NC,OR]
有没有办法在那里也包含我的子字符串否定?
I'm trying to filter all clients (using .htaccess) who try to access addresses containing for instance path=\
in the URL, but not those URL's that contain _wpnonce=1234567890
.
The logic is: block all but those who also have the _wpnonce
parameter.
The blocking, without testing if it contains the substring looks like this:
RewriteCond %{QUERY_STRING} (menu|mod|path|tag)\=\.?/? [NC,OR]
Is there a way to also include my substring negation there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档说该模式是 Perl 兼容的正则表达式,因此您应该能够使用否定先行断言:
尽管将其放在单独的
RewriteCond
中可能会更清楚,前提是您可以得到所有要计算的[OR]
。如果没有[OR]
,你可以这样写:The documentation says that the pattern is a Perl-compatible regular expression, so you should be able to use a negative lookahead assertion:
though it might be clearer to put it in a separate
RewriteCond
, provided you can get all the[OR]
s to work out. If it weren't for the[OR]
s, you could just write: