[英]IIS manager url rules for similar urls
I have two urls: http://...../m?PageView=View1&Language=English&AName=AAA and another http://...../m?PageView=View2TName=T1&AName=XYZ . 我有两个网址: http://...../m?PageView = View1&Language = English&AName = AAA和另一个http://...../m?PageView = View2TName = T1&AName = XYZ 。 Both this urls are for separate section/functionality.
这两个网址都用于单独的部分/功能。 But as the number and pattern of parameters are same one url work and another does not.
但是由于参数的数量和模式相同,因此一个网址有效,而另一个网址无效。
I want to write url redirect and rewrite rules for two similar urls. 我想为两个相似的URL编写URL重定向和重写规则。 I have written first rule as below.
我写了如下第一条规则。
<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>
and another url has same number of parameters but different name as below. 另一个网址具有相同数量的参数,但名称不同,如下所示。 Here is 2nd rule.
这是第二条规则。
<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>
When I have above two rules in web.config, one url works properly ie rediected and rewritten But another one does not work. 当我在web.config中具有以上两个规则时,一个url可以正常工作,即重新定向并重写,而另一个则不起作用。
How can I differentiate both the rules so it works for both the urls. 我该如何区分这两个规则,使其对两个URL均有效。
I solved my issue. 我解决了我的问题。 I have kept only one rule only, first one.
我只保留了一个规则,第一个。
But in my controller code actually I had to map parameters accordingly. 但是实际上在我的控制器代码中,我不得不相应地映射参数。 Means not TName parameter value I have to access, I have to access language parameter only for View-2 also, as value of TName is getting passed in Language parameter when rules get apply.
意味着我不必访问TName参数值,我也只需要访问View-2的语言参数,因为在应用规则时,TName的值将在语言参数中传递。
I could have use two rules but then I would have to change the redirect target URL. 我本可以使用两个规则,但随后必须更改重定向目标URL。 Like redirect
喜欢重定向
^View=([^=&]+)&TName=([^=&]+)&AName=([^=&]+)$ to m/{C:1}/tname/{C:2}/{C:3}
Then rewrite back from 然后从
^m/([^/]+)/tname/([^/]+)/([^/]+)/?$ to m?View={R:1}&TName={R:2}&AName={R:3}.
But I didn't wanted to have this above thing. 但是我不想拥有以上这些东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.