简体   繁体   中英

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 . 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. 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=([^=&amp;]+)&amp;Language=([^=&amp;]+)&amp;AName=([^=&amp;]+)$" />
      </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}&amp;Language={R:2}&amp;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=([^=&amp;]+)&amp;TName=([^=&amp;]+)&amp;AName=([^=&amp;]+)$" />
      </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}&amp;TName={R:2}&amp;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.

How can I differentiate both the rules so it works for both the urls.

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.

I could have use two rules but then I would have to change the redirect target 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM