This is my code for 503 page:




$protocol = "HTTP/1.0";
if ( "HTTP/1.1" == $_SERVER["SERVER_PROTOCOL"] )
$protocol = "HTTP/1.1";
header( "$protocol 503 Service Unavailable", true, 503 );
header( "Retry-After: 3600" );  

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

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

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

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

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.

  • 1
    \$\begingroup\$ Isn't if(basename($_SERVER['PHP_SELF'])=='503.php') always going to be true? \$\endgroup\$ Commented Aug 19, 2014 at 12:25
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Josh
    Commented Aug 20, 2014 at 14:00
  • \$\begingroup\$ Old but actual article from Google blog: How to deal with planned site downtime \$\endgroup\$ Commented Oct 18, 2015 at 13:55

3 Answers 3


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:

  • The error says 503, but your titles says "Page not Found"
  • Code indentation is important. Don't neglect it!
  • Never use an if block without curly brackets. Never.
  • 1
    \$\begingroup\$ "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.) \$\endgroup\$
    – MrWhite
    Commented Aug 19, 2014 at 16:39
  • 5
    \$\begingroup\$ "Never use an if block without curly brackets. Never." +1 You're a good man. \$\endgroup\$ Commented Aug 20, 2014 at 13:24

Maintenance Code

In addition to the good points of @Madara Uchiha:

You use header Retry-After in addition to http-equiv="refresh", which seems odd. The http-equiv="refresh" will redirect the user after 6 seconds to index.php, making the header Retry-After useless. The W3C recommends against using meta refresh, and I think in your situation the header Retry-After is a better solution, as first redirecting the user to 503.php, and then to index.php, from where it will probably go to 503.php again is confusing.

Of course, then you need to include instead of redirect as @Madara Uchiha recommended, otherwise the user will stay on 503.php forever. But as an include is a lot more user friendly than a redirect (user stays on page and can reload manually), this is not a problem.

SEO & Google

Returning 503 is how google recommends to handle planned downtime, so this is definitely the way to go. Google is not 100% transparent on how it determents placement in search results, but downtime is one variable that will negatively affect your standing, so try do reduce it as much as possible.


Small nitpick: You're missing the initial <html> tag.

  • 2
    \$\begingroup\$ You need to add a little bit more information than that. \$\endgroup\$
    – JaDogg
    Commented Nov 18, 2014 at 3:21
  • 1
    \$\begingroup\$ @JaDogg The answer is short, but it does suggest a concrete improvement. I think it is sufficient to be an answer. \$\endgroup\$ Commented Nov 18, 2014 at 3:35
  • 1
    \$\begingroup\$ @200_success Yes you are correct, that is a big improvement, I've also up-voted it. However adding more information will attract more up votes. \$\endgroup\$
    – JaDogg
    Commented Nov 18, 2014 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.