Forum Moderators: phranque

Message Too Old, No Replies

Database Problem - Should I return a 404 error ?

         

mark_roach

3:24 pm on Jan 21, 2009 (gmt 0)

10+ Year Member



The majority of the pages on my website are dynamically generated from a Mysql database. The page title, meta description and all of the content is read from the database.

In the event of a major problem with the database, the site is effectively down. In this instance what is the best response to give to visitors and search engines ?

I am in the process of rewriting the code and considering returning a 404 error if, for example, I cannot connect to the database. Currently I, as many other sites do, simply return a 200 OK and a page which prints the database error message.

I am trying to avoid the situation where I end up with lots of duplicate pages indexed with no content.

Is a 404 the best way to go ?

mattur

6:23 pm on Jan 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, use a "503 Service Unavailable" status code:

If your site's maintenance tasks [...] make your content temporarily unavailable, let your visitors know [...] by using the 503 HTTP status code. This will let Google know to check back later, and not index your error page as part of your site's content.

[googlewebmastercentral.blogspot.com...]

mark_roach

7:37 pm on Jan 21, 2009 (gmt 0)

10+ Year Member



Perfect.

Thanks very much.

phranque

9:43 pm on Jan 21, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i refer to the HTTP specification often in such cases to remind me of the best possible signal to provide in the response and i usually think it terms of "user agents" rather than "browsers".
the codes are described "including a description of which method(s) it can follow and any metainformation required in the response" which can be almost as important as the status code itself.

HTTP/1.1: Status Code Definitions:
[w3.org...]

here is the entry for 503 Service Unavailable [w3.org]:

10.5.4 503 Service Unavailable

The server is currently unable to handle the request due to a
temporary overloading or maintenance of the server. The implication
is that this is a temporary condition which will be alleviated after
some delay. If known, the length of the delay MAY be indicated in a
Retry-After header. If no Retry-After is given, the client SHOULD
handle the response as it would for a 500 response.

Note: The existence of the 503 status code does not imply that a
server must use it when becoming overloaded. Some servers may wish
to simply refuse the connection.