views:

929

answers:

2

RFC2616, 503 Service Unavailable

The server is currently unable to handle the request due to a temporary overloading or maintenance of the server

How to configure Apache 2.2 to serve particular name based virtualhost 503 code with custom HTML page?

+4  A: 

You could use mod_rewrite:

RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteRule !^/down/for/maintenance$ %{DOCUMENT_ROOT}down/for/maintenance [L,R=503]

The RewriteCond directive makes sure that no additional internal error occurs when redirecting to a custom error document.

Gumbo
Great, but how to specify custom "maintenance" page?
temoto
+2  A: 

@temoto

To specify a 503 for bots and a maintenance page for humans, try the following

RewriteEngine on
RewriteBase /
#for bots such as google
RewriteCond %{HTTP_USER_AGENT} ^.*(Googlebot|Googlebot|Mediapartners|Adsbot|Feedfetcher)-?(Google|Image)? [NC]
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteRule !^/down/for/maintenance$ %{DOCUMENT_ROOT}down/for/maintenance [L,R=503]

#for humans
RewriteCond %{REMOTE_HOST} !^1\.1\.1\.1
RewriteCond %{REQUEST_URI} !^/maint.html [NC]
RewriteRule .* /maint.html [R=302,L]
AlexanderN
why use a separate page for humans? 503 pages can contain content, and browsers will display it.
Carl Meyer
In some cases, tomcat may not be able to serve a 503 page. Thus, we let Apache serve a static page.
AlexanderN