htaccess重定向localhost免除

时间:2012-02-17 12:02:12

标签: .htaccess localhost

在某些时候,通过我的错误,我的localhost开始被重定向。阅读后,我将RewriteCond !localhost [NC]添加到我的.htaccess文件中,它现在看起来有效,但我几乎不知道我在做什么。

我不太了解htaccess规则,我已经阅读了几个答案并用Google搜索,但我发现的脚本似乎采取了一种不同的方法,通常是基于......

Require valid-user
Allow from 127.0.0.1
Satisfy Any

...我在整合方面遇到了麻烦。

我的修改下面是好还是坏主意?

# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^00\.00\.000\.000 # my remote IP address
RewriteCond !localhost [NC] # I added this line
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|zip) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>

1 个答案:

答案 0 :(得分:0)

我建议你删除这些行

RewriteCond %{REMOTE_ADDR} !^00\.00\.000\.000 # my remote IP address
RewriteCond !localhost [NC] # I added this line

并添加此内容:

RewriteCond %{REMOTE_ADDR} !^(?:(?:00\.00\.000\.000)|(?:127\.0\.0\.1))$

但是

Require valid-user
Allow from 127.0.0.1
Satisfy Any

解决方案要好得多。