gpt4 book ai didi

apache - 如何在Apache中实现适用于所有虚拟主机的全局RewriteCond/RewriteRule?

转载 作者:行者123 更新时间:2023-12-03 12:06:47 28 4
gpt4 key购买 nike

标题基本概括了所有内容。 :-)我有很多虚拟主机,并且我想在httpd.conf文件的顶部放置一个重写块,以重写URL,无论请求可能指向哪个虚拟主机。我该怎么办?

我找到了this,但我的问题是相同的:如何在不诉诸.htaccess文件并对每个虚拟主机执行其他操作的情况下执行此操作?

OMGTIA!

最佳答案

在父范围(例如httpd.conf)中指定RewriteOptions InheritDown,以将规则应用于子虚拟主机,而无需对其进行修改。

这仅适用于RewriteEngine指令设置为on的虚拟主机:

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.



( source)

Apache从2.4.8开始支持该功能(在最初提出问题时不可用)。

RewriteOptions的文档中:

InheritDown

If this option is enabled, all child configurations will inherit the configuration of the current configuration. It is equivalent to specifying RewriteOptions Inherit in all child configurations. See the Inherit option for more details on how the parent-child relationships are handled. Available in Apache HTTP Server 2.4.8 and later.

InheritDownBefore

Like InheritDown above, but the rules from the current scope are applied before rules specified in any child's scope. Available in Apache HTTP Server 2.4.8 and later.

IgnoreInherit

This option forces the current and child configurations to ignore all rules that would be inherited from a parent specifying InheritDown or InheritDownBefore. Available in Apache HTTP Server 2.4.8 and later.

(http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions)

关于apache - 如何在Apache中实现适用于所有虚拟主机的全局RewriteCond/RewriteRule?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/344588/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com