Scheduled maintenance with mod_rewrite
April 13th, 2008 | by dave |A public sector customer recently had a requirement to redirect visitors to one of their applications to a holding page overnight while the company who support the application carried out some maintenance work. The work was being carried out between 1am and 7am to minimize disruption to the members of public who use the application.
Keen to help, but also to get a good nights sleep we looked to mod_rewrite to provide a solution (we manage the front end servers, which run Apache).
We added the following lines to our httpd.conf to redirect any traffic to the site to a holding page at /static/offline.php from 00:55 until 07:30 to a holding page:
RewriteEngine on
RewriteCond %{TIME} >20080407055000
RewriteCond %{TIME} <20080407073000
RewriteRule !^/static/offline.php$ /static/offline.php [PT,NS]Alias /static "/var/www/www.example.com/static"
As the application sits on a Tomcat instance behind mod_proxy, we also added the following line to prevent mod_proxy from handling requests for the /static directory.
ProxyPass /static !
We created the offline.php file, including with the line below to ensure that search engines didn't index the holding page.
header("HTTP/1.1 503 Service Temporarily Unavailable")
Tags: apache, mod_rewrite, php, support, tomcat