2016-10-04 112 views
1

我改變了我的永久鏈接的結構,現在我想爲以下類型的URL重定向重定向的URL

/year/month/post-name 

這個

/post-name 

的是,可以在WordPress做或與htaccess?

+2

您的的index.php任何其他代碼下面通常不需要做任何重定向與那種永久的變化; WordPress的將處理它。刪除anubhava建議的正則表達式重寫規則,然後嘗試舊的/年/月/名稱後的鏈接並查看。 – markratledge

回答

2

你可以把這個規則爲你的第一個重定向規則(略低於RewriteEngine線):

RewriteEngine On 

RewriteRule ^/?\d{4}/\d{2}/([^/]+)/?$ /$1 [L,NC,R=301,NE] 

# rest of the WP rules 
+0

我得到一個內部服務器錯誤 –

+0

對不起,有一個錯字。現在試試我的更新規則。 – anubhava

+0

這不起作用 –

1

我發現我已經在我的開發版本中實現,但它有可能是一個解決方案從現場版本中刪除了由於WordPress更新在這裏它是。

發生之前在你的WordPress安裝

// redirect old style links to the new ones 
if (preg_match("/\/[0-9]{4}\/[0-9]{2}\//", $_SERVER['REQUEST_URI'])) 
{ 
    $newURI = '/' . preg_replace("/\/[0-9]{4}\/[0-9]{2}\//", '', $_SERVER['REQUEST_URI']); 

    header("HTTP/1.0 301 Moved Permanently"); 
    header('Location: ' . $newURI); 

    exit; 
}