IIS 7 URL Rewrite match for particular URL

被刻印的时光 ゝ 提交于 2019-12-11 04:49:57

问题


I would like to match exactly https://internet.dev.local/KYR url (without / into end) and redirect or rewrite to https://internet.dev.local/KYR/ (with /).

I am trying the following rule but it matches other URLs as well e.g. https://internet.dev.local/KYR/Admin/Form/Default.aspx?signup=false, which is wrong.

so how can I achieve this?

<rule name="Static redirect" patternSyntax="ExactMatch" stopProcessing="true">
        <match url="https://internet.dev.local/KYR" negate="true" />
        <conditions>
        </conditions>
        <action type="Redirect" url="/Login/?ReturnUrl=/Member/KYR/" redirectType="Permanent" />
      </rule>

回答1:


If you need to test the host and protocol you have to put it in the conditions, not in the global rule.
Following your example, it would be as follow:

<rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
  <match url="KYR" />
  <action type="Redirect" url="/KYR/" redirectType="Permanent" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="internet.dev.local" />
    <add input="{HTTPS}" pattern="on" />
  </conditions>
</rule>

I have changed the url in the action because your question says:
redirect or rewrite to https://internet.dev.local/KYR/ (with /).

EDIT:
To get it to work on any host (with or without SSL), just remove the conditions:

<rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
  <match url="KYR" />
  <action type="Redirect" url="/KYR/" redirectType="Permanent" />
</rule>


来源:https://stackoverflow.com/questions/14720016/iis-7-url-rewrite-match-for-particular-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!