0
我的.htaccess文件有3条重写规则,但我面临的一个问题重定向:太多的重定向错误
RewriteEngine On
RewriteBase/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REMOTE_ADDR} =IP TO BLOCK GOES HERE
RewriteCond %{REMOTE_ADDR} =ANOTHER IP TO BLOCK GOES HERE
RewriteCond %{REQUEST_URI} !^/blocked
RewriteRule ^(.*)$ http://www.myhost.com/blocked [R=307,L]
RewriteCond %{REMOTE_ADDR} !=AUTHORIZED IP HERE
RewriteCond %{REQUEST_URI} !^/maintenance
RewriteRule ^(.*)$ http://www.myhost.com/maintenance [R=307,L]
ErrorDocument 400 /400.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
的问题是,如果被阻止的IP尝试做访问该网站时,它正在维护中,我收到“错误的重定向”错误。如果IP是拒绝的ips之一,如何停止重写处理?
谢谢您的回答,这个工作,但在第一种情况下,规则以阻止IPS,htaccess的只得到了第一个,其它的被忽略,除非我用[OR]运营商。没有使用[OR]的方法吗?只是为了更直接。为什么维护规则在没有添加[OR]的情况下工作,但阻止的规则不是? – Hypister
所有测试均使用“和”。在这种情况下,您需要在多个'RewriteCond'测试中添加'[OR]'。在一次测试中可以添加多个IP:'RewriteCond%{REMOTE_ADDR} ^(111 \ .111 \ .111 \ .111 | 222 \ .22 \ .2 \ .22 | 3 \ .333 \ .33 \ .3 | xxx \ .xx \ .xxx \ .xx)$' – Croises
没有'[OR]'的维护工作,因为这是一个负面测试(使用'!')在这种情况下,您不能使用[或]。 – Croises