# Using 503 page when my site is in maintenance mode

This is my code for 503 page:

if(getOption('maintence_mode')==1)
{
exit;
}

503.php

<?php
$protocol = "HTTP/1.0"; if ( "HTTP/1.1" ==$_SERVER["SERVER_PROTOCOL"] )
$protocol = "HTTP/1.1"; header( "$protocol 503 Service Unavailable", true, 503 );
?>

<!DOCTYPE html>
<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<meta http-equiv="refresh" content="6;url=index.php">

<body>
<h2>Site is currently in maintenance mode.</h2>
</body>
</html>

I want to know if my code is correct and how Google will handle SEO thing. I don't have much knowledge about this, so it would be very helpful if someone could validate this code.

-
Isn't if(basename($_SERVER['PHP_SELF'])=='503.php') always going to be true? – Tahir Akhtar Aug 19 at 12:25 I noticed you're using a relative URI, 503.php. I suggest making it an absolute URI. To quote php.net's documentation for location: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use$_SERVER['HTTP_HOST'], \$_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself. Example code here, scroll down to second to last "Note" section. –  Josh Aug 20 at 14:00

It looks good to me, but I do have one thing to say.

If I want to access http://yourdomain.com/example/page, and get a 503 error, I want to be able to refresh the page in a little while, to see if the 503 error is lifted.

What you do is redirect the user to the 503 page, which means that the address I'll get now if I refresh is http://yourdomain.com/503.php, this is not optimal.

Instead of redirecting, include the 503 error page.

Also some other things:

• Code indentation is important. Don't neglect it!
• Never use an if block without curly brackets. Never.
-
"Instead of redirecting, include the 503 error page." - yes, as mentioned... also if you redirect the first response the client gets is a 302, not the intended 503. (Bit of an aside, but the URL in a location header should be absolute, not relative.) –  w3d Aug 19 at 16:39
"Never use an if block without curly brackets. Never." +1 You're a good man. –  FreeAsInBeer Aug 20 at 13:24

Maintenance Code