Replace 4 digit in URL by text + 4 digit

柔情痞子 提交于 2019-12-13 19:01:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!