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.

  11 Responses to “How I PHP: How to take a website offline.”

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

    ReplyReply
  2. 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. 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. That is be a nice addition Simon. I’ve changed the example accordingly.

    ReplyReply
  5. lol, as if someone was still using Apache.

    ReplyReply
  6. 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

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" extra="">

   

Questions? Just ask!

About the author

Hi, I'm Arnold Daniels. How nice that you like to know a bit more about little old me :).

I've spend a big part of my life behind a computer (and not playing games). I've learned a lot about databases, programming and system administration especially on. the LAMP stack (Linux, Apache, MySQL & PHP).

Have a look at what I'm working on now!
© 2012 Jasny · web development Suffusion theme by Sayontan Sinha