Sunday, October 28, 2007

Better Capistrano Rewrite Rule for Maintenance Page

Capistrano comes with a nice little tasked called deploy:web:disable that puts up a maintenance page on your site. Assuming your webserver detects the presence of this page and rewrites any requests to display that page, this effectively disables your site. Very handy.

I found that the common configuration available on the Internet didn't work for me. Specifically, the Apache Rewrite rule needs to reference DOCUMENT_ROOT. Here are my rewrite rules; remember that for this to work, they have to be first:

RewriteCond %{DOCUMENT_ROOT}system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ %{DOCUMENT_ROOT}system/maintenance.html [L]

3 comments:

Anonymous said...

I like to slap in a line to let through css + images too, so maintenance pages can be a bit pretty. I put the following just before your lines above:

RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$

Mike Subelsky said...

That's very timely Dr. Nic, as I was just today about to code a custom maintenance page and I'm sure that would have tripped me up. Thanks!

Eike Herzbach said...

You should prepend "system" with a "/" because the DocumentRoot should be specified without a trailing slash.