Maintenance page with .htaccess

Photo of a diversion signIn keeping with my post about hiding simple changes to a site in php, I thought I would share my method for hiding bigger changes using .htaccess.

My other method is great if you are just changing one file, but tonight I am upgrading the MediaWiki installation over at MedRevise, so I want to hide the whole site until I’m done.

I didn’t just want a blank space, so I sent my visitors to the MedRevise blog, where I put a “Sorry, I’m updating!” message, whilst keeping it so that I could still access the site myself.

How did I manage this magic? I simply changed .htaccess file to the following:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$
RewriteRule 302 [^/]*$ /blog/

I’ll take you through it:

  1. First off,
    RewriteEngine On

    turns on the Rewriting system in Apache.

  2. Then
    RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$

    tells Apache “For all ip addresses except 123.123.123.123, do the next line“.

  3. Finally  
    RewriteRule 302 [^/]*$ /blog/

    sets up a temporary rewrite of any files from root to the blog directory. The 302 redirect tells search engines that this is just a temporary redirect.

Perfection.

Image by Ian Britton. Thanks!

4 thoughts on “Maintenance page with .htaccess

Leave a Reply to Chris Lowry (@bigonroad) (@bigonroad) Cancel reply

Your email address will not be published. Required fields are marked *