2016-04-20 47 views
1

我已經構建了一個自定義的WordPress主題,顯示主頁中模式的帖子。RedirectMatch example.com/post-slug to example.com/post/post-slug

我需要重定向從

http://example.com/my-post-slug 

http://example.com/post/my-post-slug 

我試圖找出RedirectMatch,但沒有運氣。到目前爲止,我試過這個,但它只是導致一個無限循環:

RedirectMatch 301 ^/(.*)$ /post/$1 

任何幫助,將不勝感激。

回答

1

您可以在規則中使用正則表達式扭捏:

RedirectMatch 301 ^/([^/.]+)$ /post/$1 

[^/]+不會匹配/post/somepost因此不會造成任何重定向循環。確保清除您的瀏覽器緩存。

+0

這是重定向我的靜態首頁。 'example.com'轉到'example.com/post/index.php'並且它顯示'太多重定向' – pmandell

+0

在完全清除瀏覽器緩存後嘗試更新規則。 – anubhava

+1

它的工作原理!非常感謝。 – pmandell