Recently I implemented a true maintenance page on Scrawlers using Mike Clark’s excellent HOWTO. Clark’s directions show you how to create a more dynamic maintenance page than the standard HTML version we all know and love. It’s a good technique.

With those clear directions, I was most of the way there. But I still wanted our maintenance page to make use of the existing logo and stylesheets we have already created for Scrawlers. Since I’m pretty much an Apache idiot, it took some time, but I finally came up with something workable.

The maintenance rewrite conditions and rules for Apache mod_rewrite are all over the web. I’ll reprint them here for posterity.

# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]

Unfortunately, these rules do not allow for proper loading of stylesheets and images on a maintenance page. I simply repeated the above conditions, and added a RewriteRule just for stylesheets and images. JavaScript came along, too.

# Check for maintenance file and allow images, styles and javascripts
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule "^/(images|stylesheets|javascripts)/?(.*)" "$0" [L]

# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]

Of course, the DRY piece of me believes there must be a way to eliminate those redundant conditions. Near as I can tell, rewrite conditions are only applicable for the rewrite rule directly following them. So when I tried to make use of a single set of conditions to impact both rules above, well, it just didn’t work. With any luck, someone will stop by this post and show us all an improvement to this Apache configuration file.

Aug 06, 2007 · Subscribe · Archive · Projects · Twitter · GitHub · Flickr