【发布时间】:2017-12-21 01:19:21
【问题描述】:
我有两个网址:http://...../m?PageView=View1&Language=English&AName=AAA 和另一个 http://...../m?PageView=View2TName=T1&AName=XYZ。这两个网址都用于单独的部分/功能。但由于参数的数量和模式相同,一个 url 有效,另一个无效。
我想为两个相似的 url 编写 url 重定向和重写规则。我写的第一条规则如下。
<rule name="RedirectUserFriendlyURL12" stopProcessing="true">
<match url="^m/$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^View=([^=&]+)&Language=([^=&]+)&AName=([^=&]+)$" />
</conditions>
<action type="Redirect" url="m/{C:1}/{C:2}/{C:3}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL12" stopProcessing="true">
<match url="^m/([^/]+)/([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="m?View={R:1}&Language={R:2}&AName={R:3}" />
</rule>
另一个 url 具有相同数量的参数,但名称不同,如下所示。这是第二条规则。
<rule name="RedirectUserFriendlyURL12" stopProcessing="true">
<match url="^m/$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^View=([^=&]+)&TName=([^=&]+)&AName=([^=&]+)$" />
</conditions>
<action type="Redirect" url="m/{C:1}/{C:2}/{C:3}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL12" stopProcessing="true">
<match url="^m/([^/]+)/([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="m?View={R:1}&TName={R:2}&AName={R:3}" />
</rule>
当我在 web.config 中有以上两个规则时,一个 url 可以正常工作,即重新编写和重写但另一个不工作。
如何区分这两个规则,使其适用于两个 url。
【问题讨论】:
-
您能否提供您想要实现的示例或重定向?它将帮助我理解您的规则以及如何正确编写它
-
修改了顶部的问题。现在看看你能不能帮忙..
-
您的重定向不起作用?或重写不起作用?你的第二个
RewriteUserFriendlyURL12将不起作用,因为它与第一次重写具有相同的conditions和match url。并且所有请求都会被第一个RewriteUserFriendlyURL12重写 -
是的,是的...请参阅下面的回复...
标签: asp.net iis url-rewriting url-redirection iis-manager