• IIS7下WordPress中文Tag和目录无法访问完美解决方法(不修改程序)

    方法很简单。新建一个“_chineseuri.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");
    
    ?> 

    然后建立“web.config”文件,如果已经有同名文件就把原来的删掉,其内容如下:

    <configuration>   
      <system.webServer>   
        <rewrite>   
          <rules>  
          	<rule name="Chinese Tag and Category for WordPress" stopProcessing="true">
              <match url="^(tag|category)/(.*)$" />
              <action type="Rewrite" url="_chineseuri.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>

    如果你的Wordpress不是装在根目录,则需要更改“<match url="^(tag|category)/(.*)$" /> ”为“<match url="^你的目录/(tag|category)/(.*)$" /> ”。如果你把默认的标签和目录的地址改了,则更改这句话里面的对应内容即可。

    把上面两个文件上传至Wordpress所在的根目录(即web.config所在的目录)覆盖原来的文件即可。

    参考更改Wordpress源文件解决这个问题的文章,我们可以知道,是$_SERVER['REQUEST_URI']和$_SERVER['PATH_INFO']的问题。原因太多了,就不罗嗦了,想要明白解决问题的原理是什么,自己查看上面两份代码吧,呵呵。