How I PHP: How to take a website offline.

by Arnold Daniels on 06/17/2009

I’ve seen a lot of methods used to take a website temporarily off-line for maintenance. Most involve a using PHP to disable the site or renaming the index file. There is however a far better method of doing this, by placing the following in the vhost file or in an .htaccess file in the document root:

Header always set Retry-After "Thu, 18 Jun 2009 08:00:00 +0200"
Redirect 503 /

This way you are sure no part of the site is used. Also by returning a 503 http response, search-engine crawlers will not reindex your site right at the moment it is down. You can use ‘ErrorDocument’ to place a different text than the apache default.

Arnold Daniels

I've spend a big part of my life behind a computer, learning about databases (MySQL), programming (PHP) and system administration (Linux). Currently I playing with HTML5, jquery and node.js.

E-mailTwitterLinkedInGithubGittip

There are 7 comments in this article:

  1. 18 June 2009Jonathan Montgomery says:

    That’s polite, especially compared to my usual rude and brutish “deny from all”. :)

    ReplyReply
  2. 18 June 2009Simon Harris says:

    Seconded. It make a nice change to meet someone who understands HTTP.

    Of course, it would be even nicer not to take a website offline in the first place, and it’s usually avoidable with some planning :)

    ReplyReply
  3. 18 June 2009Simon Harris says:

    The thing I’d add to this though, would be that when sending a 503 it might be considered polite to also send a Retry-After header, which will give the client some idea of when the site/service will be back up.

    ReplyReply
  4. 18 June 2009Arnold Daniels says:

    That is be a nice addition Simon. I’ve changed the example accordingly.

    ReplyReply
  5. 18 June 2009jesus says:

    lol, as if someone was still using Apache.

    ReplyReply
  6. 18 June 2009Arnold Daniels says:

    What are you talking about Jesus? Almost half of all websites run on Apache. See http://news.netcraft.com/archives/2009/06/17/june_2009_web_server_survey.html

    If you have a similar solution for another webserver like Lighttpd, please add a comment supplying the comment.

    ReplyReply
  7. 16 May 2013web page says:

    Some experts also state that washing with mild soap on a damp sponge.
    While it has been exciting to see the beginnings of renewed life all around us.
    This is the least recommended method for both carpet and hardwood/tile cleaning
    flat screen monitors. The state of art cleaning flat screen monitors processes is used by many
    people. Water absorbs into the terra cotta and then freezes.

    ReplyReply

Write a comment: