Web

How To Blackout Your Website (Outage) – The Right Way

Last week we saw a mass online Blackout (#WikipediaBlackout). We also implemented a 503 Status Code Outage.

Site Temporary Unavailable

Now several people suggested methods for blackout. Lets take each of them.

1. Delete The Content

Never do this mistake. Since you dont have any files on your web folder anymore, it will return a 404 error. Now neither your visitors will see any content on your site nor any crawler/bot will be able to get anything.

2. Simple Message Post

Again, this is WRONG. This time your visitors will get the message, but the crawler/bot will access your site and consider the message as an updated post. Thus your ‘Message’ will be crawled eventually affecting search results.

3. 503 HTTP Header

Yup, The correct way.

  • It will return a 503 error to bots/crawlers, notifying them that the site is not available at the moment but will return. This way there will be no change in search results.
  • Apparently Google’s crawl rate will drop when it sees a spike in 503 errors. But this is normal and it will return to normal in a couple of days.

Robots.txt File

  • The current GoogleBot works in a way, that it will halt crawling as soon it gets 503 error for the robots.txt file of the site. It will continue to blackout untill unless it gets an acceptable code (200 or 404). So in case you plan to block a section of your website, make sure robots.txt is accessible.
  • Few webmasters use “Disallow: /” . This will simply block Google Bot from crawling your website, and there is a very high chance that crawl rate recovery can take longer than expected.

Crawl Errors

Google Webmaster Tools will report about the blackout. Make sure you keep checking the crawl errors section, for around a couple of weeks. In case of any errors, fix them / resubmit URLs.

Code Implementation

Create a 503.php file in your webroot directory, with the following code. The first two lines indicate 503 HTTP Error to the bots / crawlers and the third line informs them with a come back date-time.

<?php
header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Status: 503 Service Temporarily Unavailable");
header("Retry-After: Thu, 19 Jan 2012 00:00:00 GMT");
?>

Now you need to redirect all your visitors on that page. On a linux/apache server, its really easy. Look for .htaccess file in the webroot folder. In case you already have a configured .htaccess file for redirects etc, make sure you create a backup. Use the following code in the new .htaccess file.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^00.00.00.00
RewriteCond %{REQUEST_URI} !^/503.php [NC]
RewriteRule .* /503.php [R,L]

In case you are blocking parts of website, use absolute url instead of relative. Currently the code blocks all IPs, in case you want to access the site at all time, modify the 00.00.00.00 part to your IP in 4 set of octets.

You may want to display different message to your visitors. Just edit the 503.php like normal HTML file.

<?php
header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Status: 503 Service Temporarily Unavailable");
header("Retry-After: Thu, 19 Jan 2012 00:00:00 GMT");
?>
<!DOCTYPE html>
<html>
<head>
<title>Site is Temporary Unavailable.</title>
</head>
<body>
<h1>Site is Temporary Unavailable. </h1>
</body>
</html>

Our task is done!

Note taken using suggestions from

Tagged , , , , , , , , , ,