mod_rewrite规则覆盖所有域

时间:2022-05-16 11:20:05

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?

有没有办法在一个盒子上请求的任何域上激活RewriteRule?例如,我有5个VirtualHosts,它们具有完全相同的RewriteRule,并且当前每个VirtualHost指令都有规则,但是我可以将它放在某个“全局”的地方,以便维护更容易吗?

3 个解决方案

#1


1  

No, I'm afraid not

不,我不敢

#2


0  

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

你可以,但它有点像黑客。在.htaccess中创建您的RewriteRule,如:

/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.

现在只需将虚拟主机的DocumentRoot设置为/ www / redirects / global /,并且每个请求都将强制通过您的RewriteRule。

#3


0  

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

我还没有测试过,但是mod_rewrite文档说RewriteRule可以在服务器配置上下文中使用。

You may also want to look up how RewriteMaps 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.

您可能还想查看RewriteMaps的工作原理。由于这些文件是文件,因此可以认为它们是“全局”来源,但由于它们主要是静态的,因此存在限制。

#1


1  

No, I'm afraid not

不,我不敢

#2


0  

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

你可以,但它有点像黑客。在.htaccess中创建您的RewriteRule,如:

/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.

现在只需将虚拟主机的DocumentRoot设置为/ www / redirects / global /,并且每个请求都将强制通过您的RewriteRule。

#3


0  

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

我还没有测试过,但是mod_rewrite文档说RewriteRule可以在服务器配置上下文中使用。

You may also want to look up how RewriteMaps 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.

您可能还想查看RewriteMaps的工作原理。由于这些文件是文件,因此可以认为它们是“全局”来源,但由于它们主要是静态的,因此存在限制。