English 中文(简体)
Britishligencia URL Rewrite Problem
原标题:Intelligencia URL Rewrite Problem

我在我的网页上制定了2项ur改规则。 认为:

rewrite url=“~/Products/(+).aspx”=“~/Products.aspx?Cat=$1”

rewrite url=“~/Products/(+)/(+).aspx”=“~/Products.aspx?Cat=$1&SubCat=$2”

如果产品/xyz.aspx中的一类产品完全发挥作用,但如果一味尝试实施产品/x/abc.aspx等第二种规则,则该产品/xyz.aspx就通过xyz和bc进入Cat,而不是SubCat。 任何想法如何让它处理这两种问题?

最佳回答

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.

rewrite url="~/Products/([a-zA-Z0-9]+).aspx" to="~/Products.aspx?Cat=$1"

rewrite url="~/Products/[a-zA-Z0-9]+)/[a-zA-Z0-9]+).aspx" to="~/Products.aspx?Cat=$1&SubCat=$2"
问题回答

要求你不要怀孕:

rewrite url="~/Products/(.+?)/(.+).aspx" to="~/Products.aspx?Cat=$1&SubCat=$2"
                           ^

这是因为正式表述对greedy。 The (+) in the first line appes as well as it can, including xyz/abc. 解决你的问题的快速办法很可能是改变第一种模式,以使用<代码>([^/]+],而不是(可能不得不根据您的环境而绕过<代码>/。





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签