<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.0
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
Header Set Cache-Control "max-age=0, no-store"
</IfModule>
Create the maintenance.html
to appear how you desire. Avoid using resources from the server that is undergoing maintenance. Process images to base64 datauri or an inline SVG if possible. Styles and scripts should be inline.
To enable maintenance mode, create a file called maintenance.enable
, it just needs to exist and can be empty. Thats it!
To disable maintenance mode, either remove or rename maintenance.enable
.
RewriteEngine On
Add any IP addresses that need to gain access behind maintenance mode.
RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.0
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
Both the maintenance.html
and maintenance.enable
need to exist.
Adding, removing or renaming maintenance.enable
will be how you turn maintenance mode on/off.
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
Doing our best to avoid a redirect loop
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
503: The server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay.
This is the most appropriate status code to use for maintenance according to:
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
Header Set Cache-Control "max-age=0, no-store"