2012-05-18 43 views
0

我已經改變了我的CMS,需要寫一個mod_rewrite規則來幫助重定向一些舊的URL。試圖寫一個mod_rewrite規則

我想要做的是:

  1. 刪除 「博客/檔案」
  2. 用破折號代替下劃線
  3. 替代名 「.html」 以斜線

舊鏈接:

http://example.com/blog/archives/the_post_title.html 

新的鏈接

http://example.com/the-post-title/ 

爲了解決1 & 3我想沿着這可能工作線的東西,但它不是。

RewriteRule ^/blog/archives/([A-Za-z0-9-]+)/?.html$ $1 [L] 

感謝您的建議。

回答

0

對於1和3

RewriteRule ^/blog/archives/(.*?).html$ /$1/ [L,R=permanent] 

(注意:R =永久使用301重定向,這將被緩存很長一段時間,但不會將您的PageRank到新的URL。使用[L,R],以使用正常重定向)

+0

感謝您的開始。我寫了:'RewriteRule ^([^ _] *)_([^ _] * _。*)$ 1- $ 2 [N] \t RewriteRule ^([^ _] * )$/$ 1- $ 2 \t RewriteRule ^/blog/archives /(.*?)。html $/$ 1/[L,R = 301]' –