Windows IIS 7.5偽靜態中文URL地址404錯誤問題

來源:互聯網
上載者:User


空間遷移後,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)改了,則更改這句裡的對應內容即可。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.