2011-06-06 147 views
1

我需要幫助重定向以下URL(htaccess的).htaccess的重寫規則

http:www.domain.com/article/the-bp-oil-spill-one-year-later/19918396/20110420/ 

http:www.domain.com/article/the-bp-oil-spill-one-year-later/19918396/2011/04/20/ 

我原來改寫爲:

RewriteRule ^article/([^/]+)/([0-999999999]+)/([0-99999999]+)/?$ /index.php?a=show-post&slug=$1&articleid=$2&date=$3 [QSA,L] 

,我想消除這種模式是這樣的:

domain/2011/04/20/article-name-here/ 

感謝您對此的幫助。

感謝, 大號

+0

你的意思是「重寫」到底是什麼意思?什麼是傳入,目標URL是什麼?你有重寫已經到位嗎? – 2011-06-06 13:47:57

+0

對不起,我的錯。我編輯了這篇文章以清除自己。 – lshettyl 2011-06-06 13:50:26

+0

那麼目標網址是一個物理文件?如果不是,請顯示您已經爲此重寫的內容 – 2011-06-06 13:54:40

回答

1

你這樣的事情後:

URL Example: blah/20080101/ 

RewriteRule ^blah/([0-9]{0,4})([0-9]{0,2})([0-9]{0,2})/$ /blah/$1/$2/$3/ 

將輸出:

/blah/2008/01/01/ 
+0

絕對!非常感謝 :) – lshettyl 2011-06-06 16:14:46

0

當前/舊:/條/的-BP-溢油一年後/ 19918396/20110420/

RewriteRule ^article/([^/]+)/([0-999999999]+)/([0-99999999]+)/?$ /index.php?a=show-post&slug=$1&articleid=$2&date=$3 [QSA,L] 

期望/新:2011/04/20 /文章名,這裏/

RewriteRule ^article/([^/]+)/([^/]+)/([0-9]{0,4})([0-9]{0,2})([0-9]{0,2})/?$ /$3/$4/$5/$1 [R=301,QSA,L] 

這將允許現有的鏈接到您當前/舊樣式的URL重定向(永久)到新樣式的URL。這假定您的php應用不需要需要也將articleID傳遞給它 - 請注意,articleid不在您的新/期望的URL中。