开发者

.htaccess regex to find the last occurence for a match

I am trying to get the last occurrence of a particular match in a url, this is the line I currently have RewriteRule ^([a-zA-Z0-9\-.]+/?)$ index.php?p=$1 [QSA,L].

So for 开发者_JAVA百科example the following url /first-part/second-part/ needs to return a get variable of p='second-part' whereas /first-part/ needs to return a variable of p='first-part'


You can get what you want quite easily by removing the caret - you don't want the pattern to match from the start to the end, but just near the end:

([a-zA-Z[0-9\-.]+/?)$

Example: http://rubular.com/r/TQcppGpoq4

You may also want to remove the [ character, it looks like a mistake.
You can simplify the pattern to: ([\w\-.]+/?)$.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜