问题描述
tl;dr: 如何在 .conf 或 .htaccess 文件中执行以下操作:
tl;dr: How do I do the following in a .conf or .htaccess file:
<IfApache22>
# Do A
</IfApache22>
<IfApache24>
# Do B
</IfApache24>
更长的问题:
在 Apache 2.4 中,旧的 Order 被弃用了需要.
With Apache 2.4 the old Order get's deprecated in favor of Require.
在我的 .htaccess 文件中
In my .htaccess files I have
<FilesMatch "\.(long|list|file|types)$">
Order allow,deny
</FilesMatch>
这意味着 Apache 无法启动,除非我启用 access_compat.虽然这样做提供了一种有用的解决方法,但我想要一个可以同时使用这两种语法的解决方案,因为配置将分发到许多服务器.问题是我如何检测当前版本的 Apache 并应用正确的指令.
which means Apache fails to start unless I enable access_compat. While doing so presents a useful workaround, I want a solution that works with both syntaxes as the config will be distributed to a lot of servers. The question is how I can detect the current version of Apache and apply the correct directive.
我打算将该文件用于分发给很多人并被很多人使用的框架,我无法控制/保证他们拥有或缺少任何特定的服务器设置,这就是为什么我想要文件为 2.2/2.4不可知".
I intend to use the file for a framework that is distributed to and used by a lot of people, and I can't control/guarantee that they have or lack any particular server setup, which is why I'd like the file to be 2.2/2.4 "agnostic".
推荐答案
我用过的一个 hack.
A hack that I have used.
# Apache 2.2
<IfModule !mod_authz_core.c>
Satisfy Any
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
这篇关于在 apache 配置中检测 Apache 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!