Page 1 of 1

offline.php HTTP Status Code Suggestion (503)

Posted: Thu Dec 10, 2009 1:58 pm
by Peter Clements
When taking a Joomla! site offline, incoming requests are issued a '200 OK' HTTP Status Code but really this should be '503 Service Temporarily Unavailable'.

This can be easily achieved by adding the following code to the top of offline.php, either in the 'system' template or if you're over-riding this file with your own template, then in your own offline.php file:

Code: Select all

<?php
header('HTTP/1.1 503 Service Temporarily Unavailable',true,503);
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 86400');
?>
You can also use "Retry-After" to specify to search engines when their crawler should return to try again (in seconds).

Perhaps this should be standard in the Joomla! 'system' template?

Re: offline.php HTTP Status Code Suggestion (503)

Posted: Thu Dec 10, 2009 5:33 pm
by djohnson1215
Peter Clements,

I kind of agree, but technically, the service (from the hosting server point of view) is still available. And because a 503 error code refers to the hosting server (technically), it is not correct to apply the same code to a off-line Joomla site. In essence, the off-line condition is publishing a "parked page" which technically should produce a 200 server code.

So I think you will be hard pressed to get Joomla developers to change this condition (IMHO).

Re: offline.php HTTP Status Code Suggestion (503)

Posted: Mon Dec 14, 2009 10:04 am
by Peter Clements
I still believe that '503' is the 'most correct' and that '200' is the 'most incorrect' when taking an entire site offline temporarily. If you had it offline for long enough and returned 200 then search engines might start to cache your offline message for EVERY page of your site that it knows about.

Just had a quick look and it looks like the Google Webmaster Guidelines suggest the same too:

http://googlewebmastercentral.[URL banned]. ... lebot.html
If my site is down for maintenance, how can I tell Googlebot to come back later rather than to index the "down for maintenance" page?
You should configure your server to return a status of 503 (network unavailable) rather than 200 (successful). That lets Googlebot know to try the pages again later.
http://www.google.com/support/webmaster ... swer=40132
503 (Service unavailable) The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.
I've seen many tutorials online suggest the same too, some suggest a half-way method is to use a '307 Temporary Redirect' but you can't specify a Retry-After value and it's still not giving out the correct status IMHO.

Re: offline.php HTTP Status Code Suggestion (503)

Posted: Mon Dec 14, 2009 4:04 pm
by djohnson1215
Peter Clements,

Good evidence. Good reply. You make a good point worth of further consideration. Not sure how to get your suggestion to the developers though. May be they are listening.

Re: offline.php HTTP Status Code Suggestion (503)

Posted: Thu Dec 17, 2009 2:49 pm
by Peter Clements

Re: offline.php HTTP Status Code Suggestion (503)

Posted: Sun Feb 21, 2010 9:00 pm
by getknk
Thanks for the suggestion.

When you say top of the offline.php,
should i add below the <head> tag?

for example should i add the snippet in the first <php tag?

or anywhere in the <head> would do?
---------
Would be below example be OK?

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
<head>
<?php
header('HTTP/1.1 503 Service Temporarily Unavailable',true,503);
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 86400');
?>
	<jdoc:include type="head" />
                 .......................

Re: offline.php HTTP Status Code Suggestion (503)

Posted: Mon Feb 22, 2010 12:45 pm
by Peter Clements
getknk wrote:Thanks for the suggestion.

When you say top of the offline.php,
should i add below the <head> tag?

for example should i add the snippet in the first <php tag?

or anywhere in the <head> would do?
Make sure it's right at the top, above/before any HTML is outputted (but ensure there is no whitespace/line breaks above your DTD, close the PHP tag on the line above the DTD), below the Joomla! security check, for example mine's like this:

Code: Select all

<?php
	defined('_JEXEC') or die('Restricted access');
	
	header('HTTP/1.1 503 Service Temporarily Unavailable',true,503);
	header('Status: 503 Service Temporarily Unavailable');
	header('Retry-After: 86400');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr">
	<head>
		<jdoc:include type="head" />