我认为,标准的 Apache 表达式比重写规则更容易理解。
在维护之前,我将文件/home/coolcmd/site_maintenance_off重命名为/home/coolcmd/site_maintenance_on。
/.htaccess 的代码片段:
# If file, directory or symlink /home/coolcmd/site_maintenance_on exists,
# and requested file is not /maintenance.html,
# and not an admin's IP...
<If "-e '/home/coolcmd/site_maintenance_on' && %{REQUEST_URI} != '/maintenance.html' && %{REMOTE_ADDR} != '111.111.111.111'">
# Generate status code 503 for URL beginning with /, in other words for ANY URL.
# This is not "the real redirection 3xx".
Redirect 503 "/"
# This page handles status code 503. All external resources used by page
# (for example, maintenance.css), if any, must be added to <if> above.
ErrorDocument 503 /maintenance.html
# Maintenance probably will end in 10 minutes.
Header set Retry-After 600
</If>