开发者

Simple IIS 7 regex with optional 1, 2 or 3 values

I'开发者_开发百科m trying to make a regex match the following URL:

www.mydomain.com/newyear/food/maincourse/

and have it rewrite to default.aspx?occasion=(newyear)&type=(food)&category=(maincourse)

It works fine with:

([_0-9a-zA-Z]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/$

but I would want it to work with just www.mydomain.com/newyear/food/ as well, and just rewrite with category empty. The only way I can do this now, is by n00bing, and creating 3 rewrite rules - one for each value.

I'm pretty sure there's a smarter way, and please let me know. :)


Should be very simple, make the slashes and the last two tokens optional:

([_0-9a-zA-Z]+)/?([_0-9a-zA-Z-]*)/?([_0-9a-zA-Z-]*)/?$


If you're looking for 'less than simple', you can do unicode checking since urls can now accept them (though you may not choose them for your own domain above).

([[:alpha:]]|[[:punct:]])+/?([[:alpha:]]|[[:punct:]])*/?([[:alpha:]]|[[:punct:]])*
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜