WordPress在IIS主机下,伪静态后中文URL报404的解决方案

首先,根目录下创建index2.php,写入如下代码:文章源自原紫番博客-https://www.yuanzifan.com/54466.html

<?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内,写入如下代码(如果没有web.config,则创建)。文章源自原紫番博客-https://www.yuanzifan.com/54466.html

这个方法的好处是,不受Wordpress升级的影响,因为没有动原本的index和其他东西。文章源自原紫番博客-https://www.yuanzifan.com/54466.html

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
<rule name="ChineseURL" stopProcessing="true">
 <match url="/(tag|category)/(.*)" />
 <action type="Rewrite" url="index.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="index2.php" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
文章源自原紫番博客-https://www.yuanzifan.com/54466.html文章源自原紫番博客-https://www.yuanzifan.com/54466.html
站长微信
扫码添加(注明来意)
weinxin
Yuanzifan99
原梓番博客公众号
博客内容精选
weinxin
原梓番博客
 

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证