Mod_rewrite多次重写条件

时间:2013-04-17 14:45:47

标签: wordpress .htaccess mod-rewrite user-agent

我正在尝试以下代码仅匹配如果网址包含某些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]

由于

1 个答案:

答案 0 :(得分:0)

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

  1. 如果用户代理是-
  2. OR 如果用户代理是havij,wget等
  3. AND 如果请求 wp-login.php,wp-admin等
  4. 您需要删除否定匹配:

    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]