Setting a maintenance page in apache 2
March 15, 2007
In order to set a maintenance page in apache 2 you need:
- Enable mod_rewrite. In my debian server I just need to do the following:
ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load - Create the maintenance page somewhere in your disk server. I created it under /srv/www/maintenance
- Set up apache2 to redirect all requests to your site to the maintenance page (you will need to comment out the current apache2 directives for your website). In my case I have a /etc/apache2/sites-available/mysite file that is linked from /etc/apache2/sites-enabled/mysite.
#Maintenance page
<VirtualHost *:80>
ServerName mysite.com
ServerAdmin postmaster@mysite.com
RewriteEngine on
RewriteCond %{REQUEST_URI} !/index\.html$
RewriteCond %{REQUEST_URI} !/logo\.gif$
RewriteRule ^(.*)$ /index.html [L]
DocumentRoot “/srv/www/maintenance”
</VirtualHost> - Reload apache2 configuration:
/etc/init.d/apache2 reload
In my case I only have an index.html and a logo.gif file in the /srv/www/maintenance folder. If you have more files that are needed to render the maintenance page you will need to add some extra “RewriteCond %{REQUEST_URI} !/yourfile\.extension$” rules.
Note if you do not use the rewrite engine, the maintenance page will show up when you users access http://mysite.com or http://mysite.com/index.html, but if they access http://mysite.com/something_else they will get a nice “Page not found error”.