iis7_supports_permalinks()
云策文档标注
概述
iis7_supports_permalinks() 函数用于检查 IIS 7+ 服务器是否支持固定链接(pretty permalinks)。它通过验证 DOMDocument 类、URL Rewrite Module 1.1 和 PHP 运行模式来返回布尔值。
关键要点
- 函数返回布尔值,指示 IIS7 是否支持固定链接。
- 检查条件包括:DOMDocument 类存在、$_SERVER['IIS_UrlRewriteModule'] 已设置且 PHP 运行模式为 'cgi-fcgi'。
- 可通过 apply_filters('iis7_supports_permalinks', $supports_permalinks) 钩子过滤结果。
代码示例
function iis7_supports_permalinks() {
global $is_iis7;
$supports_permalinks = false;
if ( $is_iis7 ) {
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( 'cgi-fcgi' === PHP_SAPI );
}
return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
}注意事项
- 函数自 WordPress 2.8.0 版本引入。
- 相关函数包括 network_step2()、iis7_save_url_rewrite_rules()、got_url_rewrite() 和 redirect_canonical()。
原文内容
Checks if IIS 7+ supports pretty permalinks.
Source
function iis7_supports_permalinks() {
global $is_iis7;
$supports_permalinks = false;
if ( $is_iis7 ) {
/* First we check if the DOMDocument class exists. If it does not exist, then we cannot
* easily update the xml configuration file, hence we just bail out and tell user that
* pretty permalinks cannot be used.
*
* Next we check if the URL Rewrite Module 1.1 is loaded and enabled for the website. When
* URL Rewrite 1.1 is loaded it always sets a server variable called 'IIS_UrlRewriteModule'.
* Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
* via ISAPI then pretty permalinks will not work.
*/
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( 'cgi-fcgi' === PHP_SAPI );
}
/**
* Filters whether IIS 7+ supports pretty permalinks.
*
* @since 2.8.0
*
* @param bool $supports_permalinks Whether IIS7 supports permalinks. Default false.
*/
return apply_filters( 'iis7_supports_permalinks', $supports_permalinks );
}
Hooks
- apply_filters( ‘iis7_supports_permalinks’, bool $supports_permalinks )
-
Filters whether IIS 7+ supports pretty permalinks.
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |