检查IIS 7配置文件中是否已存在WordPress的重写规则

原型

iis7_rewrite_rule_exists( string $filename )

参数

$filename (string) (Required) 配置文件的文件路径

返回值

(bool)  

源文件

路径:wp-admin/includes/misc.php

<?php
...
function iis7_rewrite_rule_exists($filename) {
	if ( ! file_exists($filename) )
		return false;
	if ( ! class_exists( 'DOMDocument', false ) ) {
		return false;
	}
	$doc = new DOMDocument();
	if ( $doc->load($filename) === false )
		return false;
	$xpath = new DOMXPath($doc);
	$rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,'wordpress')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,'WordPress')]');
	if ( $rules->length == 0 )
		return false;
	else
		return true;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/iis7_rewrite_rule_exists/