Simple offline maintenance page for websites with .htaccess
January 11, 2017If you need to do some website or web app upgrades that require you to take the site offline you can use .htaccess so visitors are not seeing broken pages and links. This edit works great for any PHP based site, Wordpress, Codeigniter, Drupal, Expression Engine, you name it.
Create a file called offline.php (or whatever you want) and place it in your root directory and then add this to your .htaccess file.
RewriteEngine On
RewriteBase /
# for any file/folder that physically does not exist, redirect to offline
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ offline.php/$1
I you want to get a little fancier you can allow an IP so you can see the updates you are moving over while everyone else is redirected to the offline page.
RewriteEngine On
RewriteBase /
# for offline use only allow specific ip, use your ip address
RewriteCond %{REMOTE_ADDR} !=127.0.0.01
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !=/offline.php
RewriteRule .* /offline.php [L]
# redirect everyone else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ offline.php/$1