如何过滤所有包含字符串但不包含子字符串的 Apache URL

发布于 2025-01-06 05:31:52 字数 348 浏览 2 评论 0原文

我正在尝试过滤所有尝试访问 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 技术交流群。

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

发布评论

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

评论(1

吹梦到西洲 2025-01-13 05:31:52

文档说该模式是 Perl 兼容的正则表达式,因此您应该能够使用否定先行断言:

RewriteCond %{QUERY_STRING} ^(?!.*_wpnonce=1234567890).*(menu|mod|path|tag)\=\.?/? [NC,OR]

尽管将其放在单独的 RewriteCond 中可能会更清楚,前提是您可以得到所有要计算的[OR]。如果没有 [OR],你可以这样写:

RewriteCond %{QUERY_STRING} !_wpnonce=1234567890 [NC]
RewriteCond %{QUERY_STRING} (menu|mod|path|tag)\=\.?/? [NC]

The documentation says that the pattern is a Perl-compatible regular expression, so you should be able to use a negative lookahead assertion:

RewriteCond %{QUERY_STRING} ^(?!.*_wpnonce=1234567890).*(menu|mod|path|tag)\=\.?/? [NC,OR]

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:

RewriteCond %{QUERY_STRING} !_wpnonce=1234567890 [NC]
RewriteCond %{QUERY_STRING} (menu|mod|path|tag)\=\.?/? [NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文