如何使用 url rewriter.net 自动重写 url
我正在尝试重写与此模式匹配的任何 URL:
~/Ahmed
~/Name
到此:
~/User/Ahmed/Ahmed.aspx
~/User/Name/Name.aspx
我可以单独编写它们,但我想做的是检测任何看起来像 "~/User/Ahmed/Ahmed"
并自动将它们重写为 "Ahmed"
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望您使用的是 UrlRewritingNet 库,而不是 UrlRewriter?建议前者优于后者。
但是,您可以使用正则表达式:
注意 ([^/\]+) 表示任何不带斜杠的字符集,
“\1”是对前一个捕获的反向引用,确保名称完全重复。请注意,如果您想支持“/User/ahmed/Ahmed.aspx”而不仅仅是“/User/Ahmed/Ahmed.aspx”,则应该启用“忽略大小写”。
Hopefully you're using the UrlRewritingNet library, not UrlRewriter? The former is suggested over the latter.
However, in either you can use a regex:
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".