Match last occurence of 4 digits htaccess rewrite

只谈情不闲聊 提交于 2020-01-06 19:23:31

问题


I'm wondering what sort of regex I could use to match the last occurence of a set of 4 digits in my url.

My url is being formatted like this

/ARTIST/ALBUM-4 DIGITS-EXTRA STUFF

In the url, "4 DIGITS" will be the last possible occurence of 4 digits together. The thing is the ALBUM may contain sets of 4 digits, so it needs to match the last occurrence in the url.

Basically I need my rewrite rule to act as follows

RewriteRule ^(.*)/(.*)-(.* MATCH LAST OCCURENCE OF 4 DIGITS)-(.*)?$ album.php?artist=$1&album=$2&releaseyear=$3&EXTRA=$4

Is there any way to do this?


回答1:


I would use this rule:

RewriteRule ^(.*)\/(.*)-(\d{4})(?:-(.*))?$ album.php?artist=$1&album=$2&releaseyear=$3&EXTRA=$4

Try it




回答2:


You can use:

RewriteRule ^([^/]+)/(.+?)-(\d{4})-(\D*)$ album.php?artist=$1&album=$2&releaseyear=$3&EXTRA=$4 [L,QSA,NC]


来源:https://stackoverflow.com/questions/30763884/match-last-occurence-of-4-digits-htaccess-rewrite

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