Windows IIS 7.5伪静态中文URL地址链接404错误问题解决方法
IIS7.5伪静态URL_Rewrite不支持中文,下面我们来看下解决方案,希望可以帮到后来的朋友~
在WordPress安装目录下,新建一个“chineseurl.php”文件,内容如下:
如果 WordPress 不是装在根目录,则需要更改“<match url=”^(tag|category)/(.*)$” />”为“<match url=”^安装目录/(tag|category)/(.*)$” />”。如果在固定链接设置里把默认的标签前缀和分类目录前缀(tag 和 category)改了,则更改这句里的对应内容即可。
在WordPress安装目录下,新建一个“chineseurl.php”文件,内容如下:
<?php然后在web.config中新增一条规则,并将此规则置于规则集合的顶部:
// 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");
?>
<rule name="ChineseURL" stopProcessing="true">效果如下:
<match url="/(tag|category)/(.*)" />
<action type="Rewrite" url="chineseurl.php" />
</rule>
如果 WordPress 不是装在根目录,则需要更改“<match url=”^(tag|category)/(.*)$” />”为“<match url=”^安装目录/(tag|category)/(.*)$” />”。如果在固定链接设置里把默认的标签前缀和分类目录前缀(tag 和 category)改了,则更改这句里的对应内容即可。