Andre Mesquita
Andre Mesquita

Reputation: 918

How to create a EXCEPT Rewrite Rule at IIS

I have an IIS Site with Rewrite Rule to redirect all requests to HTTPS.

I have a internal web service which works with HTTP but rewrite rule modify "http" request to a "https". When happens is the web service 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 web service? how to make web service work with HTTPS protocol?

Upvotes: 0

Views: 1843

Answers (1)

Carlos Aguilar Mares
Carlos Aguilar Mares

Reputation: 13591

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>

Upvotes: 2

Related Questions