IIS 7 URL重写特定URL的匹配项 [英] IIS 7 URL Rewrite match for particular URL

查看:437
本文介绍了IIS 7 URL重写特定URL的匹配项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想完全匹配 https://internet.dev.local/ KYR url(没有/进入结束)并重定向或重写为 https://internet.dev.local/ KYR / (与/).

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 /).

我正在尝试以下规则,但它也匹配其他网址,例如 https://internet.dev.local/KYR/ Admin / Form / Default.aspx?signup = false ,这是错误的。

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.

所以我该如何实现?

<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>


推荐答案

如果你需要测试你拥有的主机和协议把它放在条件中,而不是在全局规则中。

按照你的例子,它将如下:

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>

我在动作中更改了 url 因为您的问题是:

重定向或重写为https://internet.dev.local/KYR/(带/)。

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

编辑:

要使其在任何主机上运行(使用或不使用SSL),只需删除条件:


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>

这篇关于IIS 7 URL重写特定URL的匹配项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆