Most of the docs out there about how to configure Apache for Capistrano’s deploy:web:disable task use a quick RewriteRule to the maintenance page.
That looks OK, but it doesn’t change the status code of the response: clients will usually get a 200 OK, indicating that your server is fine and that you’re sending the normal response. The correct status code to respond with is 503 Service Unavailable. With a 503, you’ll hopefully prevent search engines from indexing your maintenance page, make life easier on API consumers, enable AJAX requests to correctly deal with the site being down, and so on.
Here’s the configuration I’m using now:
1 2 3 4 5 6 7 |
# Show maintenance page if it exists
ErrorDocument 503 /system/maintenance.html
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ - [redirect=503,last] |
About that suspicious looking redirect=503 flag, here’s an excerpt from the flags section of the mod_rewrite docs:
While this is typically used for redirects, any valid status code can be given here. If the status code is outside the redirect range (300-399), then the Substitution string is dropped and rewriting is stopped as if the
Lflag was used.
So technically speaking, you can give RewriteRule anything for that second argument, and the last flag doesn’t need to be specified because it’s automatically applied. I just find it more intention-revealing to use the path “-” and stick the last flag on there anyway.

Subscribe to