开发者

how to use url rewriter.net to auto rewrite urls

i am trying to rewrite any URL that match this pattern:

~/Ahmed
~/Name

to this:

~/User/Ahmed/Ahmed.aspx
~/User/Name/Name.aspx

and i can write them individually but what i am trying to do is detect any URL that look like开发者_运维问答 "~/User/Ahmed/Ahmed" and auto rewrite them to this "Ahmed"

thanks


Hopefully you're using the UrlRewritingNet library, not UrlRewriter? The former is suggested over the latter.

However, in either you can use a regex:

"~/User/([^/\\]+)/\1.aspx"  ->  "~/$1" //For ".aspx" in the URL
"~/([A-Za-z]+)" to "~/User/$1/$1.aspx" //For /Name in the URL.

Note the ([^/\]+) means any set of characters without slashes, and "\1" is a backreference to the previous capture, that ensures the name is an exact duplicate. Note that you should enable "ignore case" if you want to support "/User/ahmed/Ahmed.aspx" and not just "/User/Ahmed/Ahmed.aspx".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜