0

我正在尝试以下代码以仅在 url 包含某些 wordpress 页面并且用户代理为空白或匹配(curl/perl/php 等)时匹配。但是,即使 REQUEST_URI 不匹配,它也会这样做。语句的流程是错误的吗?

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^-?$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (havij|libwwwperl|wget|python|nikto|curl|scan|java|winhttp|clshttp|loader) [NC]
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]

谢谢

4

1 回答 1

0

!你的正则表达式前面有一个%{REQUEST_URI}。这意味着:

  1. 如果用户代理是-
  2. 或者如果用户代理是 havij、wget 等
  3. 如果请求不是wp-login.php wp-admin 等。

您需要删除否定匹配:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^-?$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (havij|libwwwperl|wget|python|nikto|curl|scan|java|winhttp|clshttp|loader) [NC]
RewriteCond %{REQUEST_URI} ^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
于 2013-04-17T15:16:09.457 回答