In 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:
- First off,
RewriteEngine On
turns on the Rewriting system in Apache.
- Then
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$
tells Apache “For all ip addresses except 123.123.123.123, do the next line“.
- 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!
@ianbritton hey dude, thanks for the image – http://t.co/sO52Iw3
Did you get all paranoid as to whether it was working or not? I’d have gone next door to try it out 🙂
Yeh, I changed it to someone else’s ip address, then I couldn’t see the changes. But yes, it always makes me paranoid!
I was going to use this today, but the server wasn’t playing nice with my .htaccess – boo!