I have an Apache2.2 webserver set up to handle dozens of virtual host sites for our organization. I am looking for a simple method to temporarily 'turn off' all the sites by having all site requests redirect to a single "server maintenance mode" page (rather than a 404 File not found message). Is there possibly a way to do this using a mod_rewrite rule in the apache2.conf file? This would save me from having to 'touch' all these sites and turn them off individually when making changes on the server that will affect all sites.
The server setup and structure:
In the apache2.conf file the primary website is declared in the section
<VirtualHost *:80>
ServerName mainsite.org
DocumentRoot /var/www/main_site
All the other sites on the server are subdomains (abc.mainsite.org, news.mainsite.org, etc) and use standard vhost files set in /sites-available/ with a symlink in /sites-enabled/. They are activated/called by the line in apache2.conf following the VirtualHost declaration
Include /etc/apache2/sites-enabled/
I can do this for the mainsite.org by uncommenting a rewrite rule in the section that reads:
RewriteEngine on
RewriteBase /
# Redirect site requests to a 'maintenance' page
RewriteCond %{HTTP_HOST} ^www\.mainsite\.org [OR]
RewriteCond %{HTTP_HOST} ^mainsite\.org
RewriteRule ^/?(.*)$ http://kubrick.fpgsm.org [R,L]
[kubrick is the host servers name which is also placed in the 'default' vhost file as follows:]
ServerName kubrick.fpgsm.org
DirectoryIndex index.html
DocumentRoot /var/www
[index.html is where I have the 'maintenance' message.]
I have tried placing a simple rewrite rule in the which is placed above the section, but this does not work. So clearly I am missing something with regards to how the directives in apache2.conf work and/or the relationship between the VirtualHost in apache2.conf and subsequent VHost files.
RewriteCond %{HTTP_HOST} ^([a-z]+)\.mainsite\.org [NC]
RewriteRule ^/?(.*)$ http://kubrick.fpgsm.org [R,L]
Any solutions/suggestions out there? Thanks.