On this page
Apache 模块 mod_version
| Description: | 版本相关配置 |
|---|---|
| Status: | Extension |
| Module Identifier: | version_module |
| Source File: | mod_version.c |
Summary
该模块设计用于在测试套件和大型网络中使用,这些套件必须处理不同的 httpd 版本和不同的配置。它提供了一个新的容器<IfVersion>,它允许进行灵活的版本检查,包括数字比较和正则表达式。
Examples
<IfVersion 2.4.2>
# current httpd version is exactly 2.4.2
</IfVersion>
<IfVersion >= 2.5>
# use really new features :-)
</IfVersion>
参见下文了解更多可能性。
Directive
| Description: | 包含版本相关的配置 |
|---|---|
| Syntax: | <IfVersion [[!]operator] version> ... </IfVersion> |
| Context: | 服务器配置,虚拟主机,目录,.htaccess |
| Override: | All |
| Status: | Extension |
| Module: | mod_version |
<IfVersion>部分包含仅在httpd版本符合所需条件时才执行的配置指令。对于常规(数字)比较,version 参数的格式为major[.minor[.patch]],例如2.1.0或2.2。 minor 和 patch 是可选的。如果省略这些数字,则假定为零。以下数值运算符是可能的:
| operator | description |
|---|---|
=或== |
httpd 版本相等 |
> |
httpd 版本大于 |
>= |
httpd 版本大于或等于 |
< |
httpd 版本小于 |
<= |
httpd 版本小于或等于 |
Example
<IfVersion >= 2.3>
# this happens only in versions greater or
# equal 2.3.0.
</IfVersion>
除了数值比较,还可以将regular expression与 httpd 版本进行匹配。有两种编写方法:
| operator | description |
|---|---|
=或== |
版本的格式为/regex/ |
~ |
版本的格式为regex |
Example
<IfVersion = /^2.4.[01234]$/>
# e.g. workaround for buggy versions
</IfVersion>
为了反转含义,可以在所有运算符之前加上感叹号(!):
<IfVersion !~ ^2.4.[01234]$>
# not for those versions
</IfVersion>
如果省略运算符,则假定为=。