Site Down for Maintenance with htaccess
You can use Apache’s rewrite mod in your htaccess file to achieve a simple down for maintenance handler. Some scripts have this built in, some you have to roll your own. This will work with both.
The following htaccess rules will achieve the following:
1. Check the maintenance.html file exists
2. Avoid a loop and or server error by checking that the file being requested is not the maintenance.html file itself
3. Ignore requests from the site developer’s browser (that’s you so you can see the rest of the site)
4. Issue a temporary (302) redirect to everyone else’s browser to fetch the maintenance file instead.
You can modify this behaviour by:
Switching the maintenance mode on or off by renaming or deleting the maintenance file
Adding other IP address rules to permit others (developers, or clients) to view the site
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/path/to/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteCond %{REMOTE_ADDR} !123.123.123.123
RewriteRule ^(.*)$ /path/to/maintenance.html [L,R=302]
You can of course rename the maintenance.html file to anything you please.