On 23rd February I took a number of sites offline to participate in the internet blackout in protest against New Zealand copyright law. This raised an issue though - how to take a site down and replace it with one page, without changing the site itself.
With a static HTML site, you can simply backup your index.html and replace it with the temporary page. Users will still see the other pages of your site though. If you are using a CMS or blog, the solution is not quite that easy. Most dynamic web applications have an index.php file at the root that is instrumental in loading all pages of the site. Replacing this with a temporary file can lead to server errors being returned if anyone follows a backlink to the site.
What we want is to make sure all traffic ends up on the temporary page. The solution is not difficult and since it worked so well for me on a number of sites I thought I would share.
- Create your temporary file and name it index.html
- Upload this to your server
- Edit the .htaccess file in your document root and comment out any URL rewriting by adding a hash to the start of each line
eg.<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule . /index.php [L] </IfModule> - Now, redirect all traffic to the temporary index.html page
RewriteRule !^index\.html$ /index.html [L,R=302]
This rule says that if the request is not for the index.html page, then send traffic to it.
That's it! Your CMS or WordPress install is not touched but your site is effectively taken down with only the temporary page accessible. When you no longer require the temporary page, simply delete index.html from your CMS or blog site (or replace it with the original if your site uses static HTML) and revert the changes you made to your .htaccess file.
If you enjoyed this post, make sure you subscribe to my RSS feed!














{ 10 comments… read them below or jump to the comment form to add your thoughts }
Excellent Web Site! Very professional and full of great information. I am greatly enjoying it. Your enthusiasm is wonderful!!!
I just wanted to say WOW! your site is really good and i'm proud to be one of your surfers
Thank you. I'm glad you are finding it useful.
Sweet! .. thanx for that one.
Regards,
Gerard.
yeah, that worked! Thanks!
It works!
One thing though: How do you get it to redirect links that don't have the "www"? It works if the link is "http:\\www.mysite.com\etc", but can you get it to work if it's "http:\\mysite.com\etc".
Cheers,
John
Sorry, I'm very tired and I got my \\ backwards. They should be //.
Cheers,
John
@John: You could combine the htaccess directive with the no-www one from here: http://lynnepope.net/common-ca.....te-content. However, if you are only using http://example.com without the www the better way to do this is to set a CNAME record in your DNS so the www is always removed. That post also shows how to do this. It's a lot easier on your server and is a more bulletproof way of handling the domain.
Currently reading: http://lynnepope.net/redirecti.....ingle-page
Worked like a champ and was a quick-n-easy install. Thanks!
Leave a Comment