Easy Maintenance Mode with htaccess

Posted by: Alex on May 7, 2014

Many times you will want to temporarily put your site into a locked down and/or maintenance mode. This can be for a multitude of reasons, testing a brand new feature for the first time on the live server, upgrading software, migrating databases etc.

The below should be placed in your apache .htaccess file at the very top, and removed again when maintenance mode is over.

Simply add your own IP (can add multiple IPs via the separate lines as demonstrated) into the RewriteCond lines for IP and you will still be able to access and see the site, however, everyone else will just be rewritten to /maintenance.php

RewriteEngine On
RewriteBase /

#Add your IPs below, keeping the backslashes, to enable full access to site
RewriteCond %{REMOTE_ADDR} !^255\.255\.255\.255$
RewriteCond %{REMOTE_ADDR} !^100\.123\.123\.123$

#Route any request to the maintenance page if IP condition not met ... 
RewriteCond %{REQUEST_URI} !^/maintenance\.php$

#Rewrite to maintenance.php if IP condition not met
RewriteRule ^(.*)$ /maintenance.php [L]