Intelligencia URL 重写问题
我在 web.config 中创建了 2 个 url 重写规则,如下所示:
rewrite url="~/Products/(.+).aspx" to="~/Products.aspx?Cat=$1"
rewrite url=" ~/Products/(.+)/(.+).aspx" to="~/Products.aspx?Cat=$1&SubCat=$2"
如果我输入 Products/xyz.aspx 它工作正常,但如果我尝试实现第二条规则(如 Products/xyx/abc.aspx)的 url 将 xyz 和 abc 传递给 Cat 而不是 SubCat。有什么想法可以让它同时处理这两者吗?
I have created 2 url rewrite rules in my web.config that look like the following:
rewrite url="~/Products/(.+).aspx" to="~/Products.aspx?Cat=$1"
rewrite url="~/Products/(.+)/(.+).aspx" to="~/Products.aspx?Cat=$1&SubCat=$2"
If i type in Products/xyz.aspx it works perfectly but if i try a url that implements the second rule like Products/xyx/abc.aspx it passes both xyz and abc to the Cat and not the SubCat. Any ideas how i can get it to handle both?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议删除“.”上的所有匹配项。符号,因为它会让你的比赛更难预测。相反,使用涵盖您的产品类别和子类别的任何字符模式。
I suggest removing all the matching on the "." symbol as it will make your matches a bit harder to predict. Instead use whatever character patterns cover your product categories and sub-categories.
尝试使您的正则表达式非贪婪:
Try making your regex non-greedy as:
这是因为正则表达式匹配是贪婪的。第一行中的
(.+)
尽可能匹配,包括xyz/abc
。解决您的问题的快速方法可能是将第一个模式更改为使用([^/]+)
(您可能必须根据您的环境以某种方式转义/
)。That's because regular expression matching is greedy. The
(.+)
in the first line matches as much as it can, includingxyz/abc
. The quick fix for your problem is probably to change the first pattern to use([^/]+)
instead (you may have to escape the/
somehow depending on your environment).