How to create a EXCEPT Rewrite Rule at IIS

2019-09-08 08:39发布

问题:

I have a IIS Site with Rewrite Rule to redirect all requests to https.

I have a internal webservice which works with http but rewrite rule modify "http" request to a "https". When happens, webservice returns an error "Object Moved". I tried use "AllowAutoRedirect" with true value but it doesn't work.

How to create a EXCEPT Rewrite Rule to access this webservice ou how to make webservice work with https protocol?

Thanks!

Best Regards,

Andre Mesquita

回答1:

One way is to add the rule before the "global redirect" and make sure to use stopProcessing="true" so that the next rule is not executed, for example the following rule will allow HTTP only on requests to the segment "foo/", everything else will redirect to 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>