我想要一个mod_rewrite规则,当stream量从内部networking到达networking服务器时不会被执行。 Web服务器是apache 2.2下面的RewriteCond是为了防止重写规则。
RewriteCond %{REMOTE_ADDR} !=192\.168\.[0-15]\.[1-255]
如果我使用ip 192.168.15.173访问web服务器,规则似乎没有踢,因此尽pipe我的内部地址执行重写规则。 我的错误在哪里?
匹配更简单:
RewriteCond %{REMOTE_ADDR} !=192\.168\.15\.173
也失败了。
我使用http://httpd.apache.org/docs/trunk/rewrite/access.html中的“Blocking of Robots”示例来构build规则。 我错过了什么吗?
编辑:我已经试图调查使用重写日志,但没有提出任何有用的信息。 这是请求过程中发生的事情:
192.168.15.173 - - [12/Jun/2013:13:50:17 +0200] [example.com/sid#7f3c6afb5e30][rid#7f3c6f864b68/initial] (2) init rewrite engine with requested uri /test/ 192.168.15.173 - - [12/Jun/2013:13:50:17 +0200] [example.com/sid#7f3c6afb5e30][rid#7f3c6f864b68/initial] (3) applying pattern '^/test/(.*)' to uri '/test/' 192.168.15.173 - - [12/Jun/2013:13:50:17 +0200] [example.com/sid#7f3c6afb5e30][rid#7f3c6f864b68/initial] (2) rewrite '/test/' -> 'https://example2.com/' 192.168.15.173 - - [12/Jun/2013:13:50:17 +0200] [example.com/sid#7f3c6afb5e30][rid#7f3c6f864b68/initial] (2) explicitly forcing redirect with https://example2.com/ 192.168.15.173 - - [12/Jun/2013:13:50:17 +0200] [example.com/sid#7f3c6afb5e30][rid#7f3c6f864b68/initial] (1) escaping https://example2.com/ for redirect 192.168.15.173 - - [12/Jun/2013:13:50:17 +0200] [example.com/sid#7f3c6afb5e30][rid#7f3c6f864b68/initial] (1) redirect to https://example2.com/ [REDIRECT/302]
我甚至没有看到在这个日志中提到的RewriteCondition。
编辑2:详细的Apache版本是:
Name : httpd Arch : x86_64 Version : 2.2.15 Release : 26.el6.centos Size : 2.9 M Repo : installed From repo : anaconda-CentOS-201303020151.x86_64
Edit3:我把LogLevel提高到了4,现在我得到了更多的结果:
192.168.15.173 - - [12/Jun/2013:14:18:05 +0200] [example.com/sid#7f3c6afdfdb0][rid#7f3c6f880568/initial] (4) RewriteCond: input='192.168.15.173' pattern='!=192\.168\.15\.173' => matched
为什么这个匹配?
编辑4: http: //regexr.com?356tm告诉我,它不应该匹配…
我find了我的问题的答案。 正确的条件应该是:
RewriteCond %{REMOTE_ADDR} !192\.168\.[0-9]+\.[0-9]+