IIS WordPress 单站点,多站点 中文URL乱码和重定向多次问题解决方法

时间:2023-02-04 08:01:20


前提是需要安装 IIS URL 重写组件 (安装方法这里不说明,搜一下资料就有)

IIS WordPress 单站点,多站点 中文URL乱码和重定向多次问题解决方法

1、站点网站根目录新增一个 chineseurl.php 文件用来处理中文url问题

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


2、单站点网络 web.conf 配置修改

在rules 标签下添加以下规则即可:

<rule name="ChineseURL" stopProcessing="true">

<match url="^(.*)$"/>

<conditions>

<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>

<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>

</conditions>

<action type="Rewrite" url="chineseurl.php"/>

</rule>


<rule name="WordPress: https://www.isaf.gov.mo" 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>

3、IIS wordpress 多站点网络 web.conf 配置修改

主要修改 wordpress Rule 6 多站点 规则,将其重定向为 chineseurl.php 文件 即可

将后面  <action type="Rewrite" url="index.php" />   改为  <action type="Rewrite" url="chineseurl.php" />   注意:如果不修改打开多站点会出现 重定向多次的严重错误

最终效果如下 :

<rules>
<rule name="WordPress Rule 1" stopProcessing="true">
<match url="^index\.php$" ignoreCase="false" />
<action type="None" />
</rule>

<rule name="WordPress Rule 2" stopProcessing="true">
<match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
<action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
</rule>

<rule name="WordPress Rule 3" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>

<rule name="WordPress Rule 4" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
<add input="{URL}" pattern="([a-zA-Z0-9\./_-]+)\.axd" />
</conditions>
<action type="None" />
</rule>
<rule name="WordPress Rule 5" stopProcessing="true">
<match url="^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*)" ignoreCase="false" />
<action type="Rewrite" url="{R:1}" />
</rule>
<rule name="WordPress Rule 6" stopProcessing="true">
<match url="." ignoreCase="false" />
<action type="Rewrite" url="chineseurl.php" />
</rule>