Setting a maintenance page in apache 2

March 15, 2007

In order to set a maintenance page in apache 2 you need:

  1. 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
  2. Create the maintenance page somewhere in your disk server. I created it under /srv/www/maintenance
  3. 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>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/index\.html$
    RewriteCond %{REQUEST_URI} !/logo\.gif$
    RewriteRule ^(.*)$ /index.html [L]
    DocumentRoot “/srv/www/maintenance”
  4. 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 or, but if they access they will get a nice “Page not found error”.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: