我要讓重定向從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]
,但它不工作。 你能幫我解決嗎?
我要讓重定向從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]
,但它不工作。 你能幫我解決嗎?
你不需要RewriteCond %{HTTP_HOST}
爲你匹配REQUEST_URI
,你可以在RewriteRule
自己做。
您可以在網站根目錄的.htaccess使用這樣的規則:
RewriteEngine On
RewriteRule ^(.+)/([0-9]+)/?$ /$1/ [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^(.*)/([0-9]+)/?$
而不是:
RewriteCond %{HTTP_HOST} ^(.*)([0-9]*)/$
您還可以使用RedirectMatch
RedirectMatch 301 ^/(.+)/([0-9]+)/?$ /$1
很多很多的感謝!完美的作品! –