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

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

  1. <?php
  2.  
  3. // IIS Mod-Rewrite
  4.  
  5. if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
  6.  
  7. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
  8.  
  9. }
  10.  
  11. // IIS Isapi_Rewrite
  12.  
  13. else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
  14.  
  15. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
  16.  
  17. } else {
  18.  
  19. // Use ORIG_PATH_INFO if there is no PATH_INFO
  20.  
  21. if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
  22.  
  23. $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
  24.  
  25. // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
  26.  
  27. if ( isset($_SERVER['PATH_INFO']) ) {
  28.  
  29. if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
  30.  
  31. $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
  32.  
  33. else
  34.  
  35. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
  36.  
  37. }
  38.  
  39. // Append the query string if it exists and isn't null
  40.  
  41. if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
  42.  
  43. $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
  44.  
  45. }
  46.  
  47. }
  48.  
  49. require("index.php");
  50.  
  51. ?>

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

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

  1. <configuration>
  2. <system.webServer>
  3. <rewrite>
  4. <rules>
  5. <rule name="ChineseURL" stopProcessing="true">
  6. <match url="/(tag|category)/(.*)" />
  7. <action type="Rewrite" url="index.php" />
  8. </rule>
  9. <rule name="wordpress" patternSyntax="Wildcard">
  10. <match url="*" />
  11. <conditions>
  12. <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  13. <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  14. </conditions>
  15. <action type="Rewrite" url="index2.php" />
  16. </rule>
  17. </rules>
  18. </rewrite>
  19. </system.webServer>
  20. </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:
确定

拖动滑块以完成验证
加载中...