503 HTTP Status Code when Site Down
If for some reason you must take down your site or just a few pages temporarily for maintenance, moving servers, or whatever reason, you need to tell the search engines that this is TEMPORARY. Otherwise, they will see the page is not there (404 status/response code) and drop your site or page from their search index. This would obviously not be good.
You tell the search engine that the page is temporarily unavailable using the 503 status code in the http header. In php, you can set the header for the status code like:
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 7200'); // in seconds
In drupal, you can use the equivalent, drupal_set_header function.
You can use .htaccess rules in combinations with a php file to use the 503 status code by:
1) Create a 503 php code page (e.g. error503.php) and put the header code in it like:
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 7200'); // in seconds
print "This page is temporarily unavailable";
2) In the .htaccess file, add in:
RewriteRule .* /[path-to-file]/error503.php
(This will redirect all pages to your error503.php file.)
Or you can only redirect specific pages to the file like:
RewriteRule page.html /[path-to-file]/error503.php
In Drupal, you can use your tpl.php files to deal with returning status codes if you need to. For example, in page.tpl.php, you could do:
<?php
drupal_set_header('HTTP/1.1 503 Service Temporarily Unavailable');
drupal_set_header('Status: 503 Service Temporarily Unavailable');
drupal_set_header('Retry-After: 7200'); // in seconds
print "This page is temporarily unavailable";
?>
Or set up whatever logic makes sense... For example, if all blog pages need to be down and they have a url alias path like "blogs/xxx", you could do
<?php
if (arg(0) == 'blogs') {
// same code as above
return;
}
?>
Using the correct http status codes is very important for SEO. For pages that are temporarily down, use the 503 status code. For pages with new URLs, use the 301 permanent redirect. In Drupal, you can use the Global Redirect module, Path Redirect module, and Search 404 module to help with managing your status codes efficiently.
Comments
Ths is superb..this is exactly what I needed.
Thank you Kristen. This was very helpful. Did not find much on this on drupal.org and your information was golden .. exactly what I was looking for.
-James.
Cool
Glad to hear it ;)
Post new comment - ALL COMMENTS ARE MODERATED - SPAM WILL BE DELETED!