简体   繁体   中英

mod_rewrite Rule to Cover All Domains

Is there a way to have a RewriteRule fire on any domain that is requested on a box? For example, I have 5 VirtualHosts that would have the exact same RewriteRule applied to them and currently each VirtualHost directive has the rule, but can I put this somewhere 'global' so that upkeep is easier?

不,恐怕不是

You can, but it is somewhat of a hack. Create your RewriteRule in a .htaccess somewhere like:

/www/redirects/global/.htaccess

Now just set the DocumentRoot for your virtualhosts to /www/redirects/global/ and every request will be forced through your RewriteRule's.

I haven't tested it, but the mod_rewrite docs say that RewriteRule can be used in the server config context.

You may also want to look up how RewriteMap s work. Since these are a file, they could be considered to be a "global" source, but there are limitations on them since they are primarily static.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM