如何过滤所有的Apache URL包含字符串但不包含子 [英] How to filter all Apache URL containing string but not containing a substring
问题描述
我试图过滤所有客户端(使用的.htaccess),谁试图访问包含例如地址 =路径\
中的URL,而不是那些网址包含 _wpnonce = 1234567890
。
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
.
的逻辑是:阻止所有,但那些谁也有_wpnonce 参数。
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?
推荐答案
该文件说,该模式是一个Perl兼容的正前pression,所以你应该能够使用负预测先行断言:
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]
尽管它可能更清楚把它放在一个单独的的RewriteCond
,只要你可以得到所有的 [OR]
s到工作了。如果不是为 [OR]
S,你可以这样写:
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]
这篇关于如何过滤所有的Apache URL包含字符串但不包含子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!