Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

how can I redirect traffic of all websites (and not one of them) to a page in apache2 conf file?

the goal is creating a maintenance page for all domains.

share|improve this question

2 Answers 2

You need to use the following rewrite rules:

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/maintenance.html
RewriteRule ^ /maintenance.html [R=301]

This should redirect all requests to the maintenance.html page.

share|improve this answer
    
the goal is creating a maintenance page for "all domains". this not work for all of them. –  exim Jan 1 '13 at 8:50
    
@exim This does work for all domains but you will have to put it in a part of your configuration that applies to all domains. If you have one vhost per domain, putting this in just one of them will not work. I would also avoid using a 301 redirect, or even a redirect at all. Just serve up the maintenance page under the URL that was requested with a 503 response code. –  Ladadadada Jan 1 '13 at 21:38
    
@Ladadadada I know that solution but I want a better solution for all vhosts to use in a cronjob before proccessing schedule backups –  exim Jan 2 '13 at 8:38
    
It's generally a good idea to put all of your requirements in the question to save this back-and-forth extraction process. –  Ladadadada Jan 2 '13 at 9:14
    
@Khaled Nice answer, although a 301 redirect to a maintenance page would be killing for your SEO if a crawler would come by at that point. I know it's just an example, but this is just a note to anyone who considers implementing something like this. –  Oldskool Jan 2 '13 at 9:55

To easily change many vhosts, add this to all of them (you only need to do this once):

Include maintenance-status.conf

Add something like @Khaled's answer in /etc/apache2/maintenance-on.conf.

Create a symlink at /etc/apache2/maintenance-status.conf pointing at /etc/apache2/maintenance-off.conf, which should be an empty file.

In your cron job, simply repoint that link at the beginning and end and give Apache a graceful restart after each one.

It might be better to do this in PHP (or whatever scripting language you use) and trigger it with a file or a database entry if you can.

share|improve this answer
    
good solution but I can not use such rewrite commands that khaled said in a conf file. those works in local .htaccess file and pointed to local file (index.html). even if I do it, then how I discard all other rewrite mod commands came from local htaccesses? –  exim Jan 2 '13 at 13:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.