站点下来进行维护

时间:2010-09-22 06:58:13

标签: apache mod-rewrite

我的网站排列如下,子域名为子目录:

/ [webroot]
/subdomain1/
/subdomain2/

我想创建一个htaccess文件,将所有访问过的文件重写为maintenance.php w / 503消息,但我不确定为什么以下内容没有捕获子目录?

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^111\.222\.333\.444$ 
RewriteCond %{REQUEST_URI} !^/maintenance\.php$
RewriteRule ^(.*)$ /maintenance.php [L]

我是否必须将每个子目录称为......

RewriteRule ^/subdirectory1(.*)$ /maintenance.php [L]
RewriteRule ^/subdirectory2(.*)$ /maintenance.php [L]

2 个答案:

答案 0 :(得分:1)

这应该有效:

RewriteEngine On
RewriteCond %{REMOTE_HOST} !^111\.222\.333\.444
RewriteCond %{REQUEST_URI} !/maintenance.php$
RewriteRule $ /maintenance.php [L]

答案 1 :(得分:0)

如果您的子目录中有其他htaccess文件,则必须在删除该文件后查看更改。如果htacess控制重写,则在查看这些页面时可能会收到404错误。

我期待看到维护页面,没有意识到我需要根据以下代码拥有不同的IP地址:

此代码允许您的IP查看该网站,而不是其他人:

RewriteEngine On
RewriteBase /

#ip is not your ip. Change ip to see maintenance page
RewriteCond %{REMOTE_ADDR} !^111\.222\.333\.444$

#requests made not to maintenance.php ... 
RewriteCond %{REQUEST_URI} !^/maintenance\.php$

#rewrite to maintenance.php
RewriteRule ^(.*)$ /maintenance.php [L]