2011-12-26 54 views
0

我一直在研究重定向幾天,現在仍在掙扎,所以我決定在這裏發佈我的第一個問題。出於某種原因,它只是不點擊我。301重定向到更改結構

我重新設計並開發了一個客戶端的WordPress網站,需要更新它的結構。

該網站目前的結構是: www.domain.com/blog/postname/2011/12/26/

新的結構應該是: www.domain.com/blog/postname

我真的認爲這會很容易,因爲我所要做的就是放棄日期,但無法掌握整個通配符方面以及如何結束我想要匹配的內容。任何幫助將不勝感激。一個簡單的答案很棒,但解釋會更好。

+0

簽名被刪除,請參閱FAQ。 – 2011-12-27 15:23:33

回答

1

我假設你已經知道如何改變你的WordPress永久鏈接結構來刪除日期。

要301將所有舊網址重定向到新網址,請將以下規則添加到您的網站域根目錄中的.htaccess文件中,並超出所有現有規則。

#if these 2 lines already exist, skip them and add the rest 
RewriteEngine on 
RewriteBase/

# if there is a request of the form /blog/post-name/yyyy/mm/dd/ 
RewriteCond %{REQUEST_URI} ^(/blog/[^/]+/)[0-9]{4}/[0-9]{2}/[0-9]{2}/$ [NC] 
#redirect the request to the URL without the date 
RewriteRule . %1 [L,R=301] 

如果您想了解更多有關的.htaccess /重寫你可以在以下網址看看:Indepth htaccessBrief Introduction to RewritingApache Mod_rewrite

讓我知道這是否適用於您和/或您有任何問題。

+0

這工作完美!非常感謝。 我試圖做到這一點沒有一個RewriteCond這顯然是不正確的。我非常感謝你的時間和與其他資源的聯繫。 再次感謝和節日快樂! Bart – 2011-12-27 02:39:47