空間遷移後,WordPress文章中所有的中文tag頁面訪問全都報404錯誤,Google搜尋了一下,得知IIS7.5偽靜態URL_Rewrite不支援中文,最終在IIS7 WordPress 中文 URL 解決方案博文中找到解決方案,特別感謝原文作者,在此將解決方案再分享一下,希望可以幫到後來的朋友~
在WordPress安裝目錄下,建立一個“chineseurl.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中新增一條規則,並將此規則置於規則集合的頂部:
代碼如下 |
複製代碼 |
<rule name="ChineseURL" stopProcessing="true"> <match url="/(tag|category)/(.*)" /> <action type="Rewrite" url="chineseurl.php" /> </rule>
|
效果如下
如果 WordPress 不是裝在根目錄,則需要更改“<match url=”^(tag|category)/(.*)$” />”為“<match url=”^安裝目錄/(tag|category)/(.*)$” />”。如果在固定連結設定裡把預設的標籤首碼和分類目錄首碼(tag 和 category)改了,則更改這句裡的對應內容即可。