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.
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:
This command will insert line
include /some/where/rewrite.conf
after each occurence ofmatchstring
in all /etc/apache2/vhosts/*.conf files.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 usesed -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.