Windows IIS 7.5中文URL404问题解决方案

空间迁移后,WordPress文章中所有的中文tag页面访问全都报404错误,Google搜索了一下,得知IIS7.5伪静态URL_Rewrite不支持中文,最终在IIS7 WordPress 中文 URL 解决方案博文中找到解决方法,特别感谢原文作者,在此将解决方案再分享一下,希望可以帮到后来的朋友~

在WordPress安装目录下,新建一个“chineseurl.php”文件,内容如下:

<?php

// IIS Mod-Rewrite
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
}
// IIS Isapi_Rewrite
else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}
else
{
// Use ORIG_PATH_INFO if there is no PATH_INFO
if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
$_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];

// Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
if ( isset($_SERVER['PATH_INFO']) ) {
if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
else
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
}

// Append the query string if it exists and isn't null
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}

require("index.php");

?>

然后在web.config中新增一条规则,并将此规则置于规则集合的顶部:


<rule name="ChineseURL" stopProcessing="true">
 <match url="/(tag|category)/(.*)" />
 <action type="Rewrite" url="chineseurl.php" />
</rule>

效果图如下:

http://xzh.i3geek.com
Back to Top