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.

To fix a security problem I need to add some rewrite rules to all our virtual host configurations.

Are there any options adding rewrite rules to all virtual host declarations besides updating to every single one?

Update:

The reference docs states: Note that rewrite configurations are not inherited by virtual hosts. This means that you need to have a RewriteEngine on directive for each virtual host in which you wish to use rewrite rules.

I'm not sure wheter this means the general rewrite rules are not taken into account for virtual hosts.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Can you use include directive in vhost configuration and put your rewrite rules in separate file?

You can mass edit your vhost configuration file using sed:

sed -i.bak '/matchstring/ a\
include /some/where/rewrite.conf' /etc/apache2/vhosts/*.conf

This command will insert line include /some/where/rewrite.conf after each occurence of matchstring in all /etc/apache2/vhosts/*.conf files.

share|improve this answer
add comment

Do the rewrites have to go inside the vhosts or can you put the rewrite rule(s) in the main httpd.conf file? Rewrites there apply to all requests, regardless of which vhost they apply to.

If they have to go in the vhosts, are all the rewrites exactly same or do they depend in the vhost/ServerName/ServerAlias? You could use sed -i to modify any number of files if the rewrite is exactly the same in every file.

If the rewrite needs to be different in every file (or if the vhosts are all different), there may be no easy way. You may be able to use sed -i again in a bash loop over the names of the files but without knowing the specific details of the changes you need to make there's not much we can recommend.

share|improve this answer
    
If I put the rewrite rules in the general httpd.conf file, nothing happens. If I put them into a virtual host they work fine. My guess is that virtual hosts don't inherit gloab rewrite rules. –  BetaRide May 21 '12 at 12:16
add comment

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.