2016-06-13 12 views
3

我要讓重定向從URL中像的.htaccess從數字在年底

/test/112321 to /test/ 
/test/test2/1311223 /test/test2/ 

只有在URL的末尾位數重定向。

現在我有

RewriteCond %{HTTP_HOST} ^(.*)([0-9]*)/$ [NC] 
RewriteRule ^(.*)/([0-9]*)$ http://%1/$1/ [R=301,L] 

,但它不工作。 你能幫我解決嗎?

回答

2

你不需要RewriteCond %{HTTP_HOST}爲你匹配REQUEST_URI,你可以在RewriteRule自己做。

您可以在網站根目錄的.htaccess使用這樣的規則:

RewriteEngine On 

RewriteRule ^(.+)/([0-9]+)/?$ /$1/ [R=301,L,NE] 
+1

很多很多的感謝!完美的作品! –

1
RewriteCond %{HTTP_HOST} ^(.*)/([0-9]+)/?$ 

而不是:

RewriteCond %{HTTP_HOST} ^(.*)([0-9]*)/$