使用 Mod_Rewrite 进行临时维护

Avatar of Chris Coyier
Chris Coyier
# Don't forget to turn on the rewrite engine
RewriteEngine on

# Maintenance Redirection
# Replace 555\.555\.555\.555 with your own IP address
# Uncomment first conditional to turn off the redirection
# RewriteCond %{REQUEST_URI} ^$a
RewriteCond %{REQUEST_URI} !maintenance.html
RewriteCond %{REQUEST_FILENAME} !(styles|images).+$
RewriteCond %{REMOTE_ADDR} !^555\.555\.555\.555$
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteRule (.*) /maintenance.html [R,L]

此代码使您可以轻松地暂时关闭网站以进行更新。将“555”行替换为您自己的IP地址,以便您在其他人被重定向时仍能正常查看网站。图像和样式也可以通过过滤器传递。

第一个注释条件旨在始终失败,因此关闭此重定向只需取消注释该行即可。