IIS 7 重写规则 - 重写同一页,一个或多个查询字符串参数
IIS 7 rewrite rule - rewrite same page, one or multiple query string parameters
我有以下重写规则设置
<rule name="Department Rewrite" stopProcessing="true">
<match url="^products/([^$]+)" />
<action type="Rewrite" url="products?durl={R:1}" />
</rule>
<rule name="Product Rewrite" stopProcessing="true">
<match url="^products/([^$]+)/([^$]+)" />
<action type="Rewrite" url="products?durl={R:1}&purl={R:2}" />
</rule>
部门重写按预期工作,现在我正在尝试配置产品重写以工作。
随着URLproducts/department
- Request.QueryString["durl"]输出部门
与URLproducts/department/product
- Request.QueryString["durl"] 输出 department/product
- Request.QueryString["purl"] 为 NULL
如何让产品重写按预期工作?
更新
同时研究如何忽略包含 action/edit
的 URL 重写。例如
products/department/action/edit
products/department/product/action/edit
假设我需要应用一些条件语句但不确定如何编写它们。
[^$]
想做什么?
在部门重写中,第一组说 "matching anything but a $",这是 url 的其余部分,因此应用了该规则,并且全部在 durl.
中
试试这些 "match anything but a slash"。我也喜欢用 $ 来结束它,如果你知道那是完整的 url(它仍然可以有查询字符串参数)。这将使产品跳过部门规则。
在部门规则中:
<match url="^products/([^/]+)$" />
在产品规则中:
<match url="^products/([^/]+)/([^/]+)$" />
我喜欢两组相同的一致性,但你可以让第二组取任何东西,为了更简单的规则:
<match url="^products/([^/]+)/(.+)" />
附带建议:先把具体的规则放上去,如果只发一个级别(部门)肯定不符合产品规则。现在的样子,部门抢了产品法则。如果它们被逆转,它可能会起作用,即使没有更新规则。
我有以下重写规则设置
<rule name="Department Rewrite" stopProcessing="true">
<match url="^products/([^$]+)" />
<action type="Rewrite" url="products?durl={R:1}" />
</rule>
<rule name="Product Rewrite" stopProcessing="true">
<match url="^products/([^$]+)/([^$]+)" />
<action type="Rewrite" url="products?durl={R:1}&purl={R:2}" />
</rule>
部门重写按预期工作,现在我正在尝试配置产品重写以工作。
随着URLproducts/department
- Request.QueryString["durl"]输出部门
与URLproducts/department/product
- Request.QueryString["durl"] 输出 department/product
- Request.QueryString["purl"] 为 NULL
如何让产品重写按预期工作?
更新
同时研究如何忽略包含 action/edit
的 URL 重写。例如
products/department/action/edit
products/department/product/action/edit
假设我需要应用一些条件语句但不确定如何编写它们。
[^$]
想做什么?
在部门重写中,第一组说 "matching anything but a $",这是 url 的其余部分,因此应用了该规则,并且全部在 durl.
试试这些 "match anything but a slash"。我也喜欢用 $ 来结束它,如果你知道那是完整的 url(它仍然可以有查询字符串参数)。这将使产品跳过部门规则。
在部门规则中:
<match url="^products/([^/]+)$" />
在产品规则中:
<match url="^products/([^/]+)/([^/]+)$" />
我喜欢两组相同的一致性,但你可以让第二组取任何东西,为了更简单的规则:
<match url="^products/([^/]+)/(.+)" />
附带建议:先把具体的规则放上去,如果只发一个级别(部门)肯定不符合产品规则。现在的样子,部门抢了产品法则。如果它们被逆转,它可能会起作用,即使没有更新规则。