如何在 IIS 中创建 EXCEPT 重写规则

How to create a EXCEPT Rewrite Rule at IIS

我有一个带有重写规则的 IIS 站点,可以将所有请求重定向到 https。

我有一个使用 http 的内部网络服务,但重写规则将 "http" 请求修改为 "https"。发生时,webservice returns 错误 "Object Moved"。我尝试将 "AllowAutoRedirect" 与真值一起使用,但它不起作用。

如何创建 EXCEPT 重写规则来访问此 Web 服务或如何使 Web 服务使用 https 协议?

谢谢!

此致,

安德烈·梅斯基塔

一种方法是在 "global redirect" 之前添加规则,并确保使用 stopProcessing="true" 以便不执行下一条规则,例如,以下规则将仅允许对段 "foo/" 的请求使用 HTTP,其他所有内容都将重定向到 SSL:

<rewrite>
  <rules>
    <rule name="Allow requests to the folder foo over non-https" stopProcessing="true">
      <match url="^foo/.*" />
      <action type="None" />
    </rule>
    <!-- Else redirect ALL request to HTTPS -->
    <rule name="Redirect to https">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="Off" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>