问题
Using .htaccess, I need to replace the following URL:
www.domain.com/1234-text....
By:
www.domain.com/item/1234-text....
This is what I'm trying:
RewriteRule ^[0-9][0-9][0-9][0-9]-/(.*)$ https://www.domain.com/item/[0-9][0-9][0-9][0-9]-/$1 [R=301,L]
I've been exploring the Regex wiki but couldn't find the right expression.
回答1:
Try this rule:
RewriteRule ^(\d{4}-.*)$ /item/$1 [R=301,L]
回答2:
Try instead:
RewriteRule ^([0-9]{4}\-.*)$ https://www.domain.com/item/$1 [R,L]
来源:https://stackoverflow.com/questions/33628668/replace-4-digit-in-url-by-text-4-digit