最新消息:

轻松解决GodaddyMianFei空间win主机IIS7.X下wordpress伪静态中文标签404错误问题

IIS William 3042浏览

在成功在GodaddyMianFei赠送的Win空间上面安装WordPress并解决了在GodaddyMianFei赠送的Win空间上面配置IIS7.x伪静态后,笔者以为博客已经可以完美支持伪静态运行,可没想到偶然的机会点了一个中文的tag标签之后,如/post-tag/MianFei空间,发现出现了404错误,又试了几个其它的中文标签,一样有错误,再试英文的标签却很正常,笔者马上意识到是这是GodaddyMianFei空间win主机的IIS7.X伪静态不支持中文标签造成的。出现了这个问题必须立马解决掉。
于是检查伪静态配置文件,百度谷歌几个,最后终于解决了。

没时间细说怎么解决的了,就直接上代码吧,把以下的web.config和rewrite.php上传到安装目录就可以了。

web.config代码:

 <?xml version="1.0"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
<rewrite>
<rules>
<clear/>
<rule name="ChineseURL" stopProcessing="true">
<match url="^(post-tag|tag|category|post-category)/(.*)$" />
<action type="Rewrite" url="rewrite.php"/>
</rule>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

rewrite.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");
?>

此代码只对wordpress安装在要根目录有效,不在根目录的需要修改伪静态规则。

PS:本配置可能仅对部分IIS7.X下安装的wordpress有效。

希望代码对你有用。

转载请注明:AspxHtml学习分享网 » 轻松解决GodaddyMianFei空间win主机IIS7.X下wordpress伪静态中文标签404错误问题