Redirect to HTTP behind load balancer (apart from localhost) with URL rewrite

Datetime:2016-08-22 22:57:26         Topic:         Share        Original >>
Here to See The Original Article!!!

Just a short "note to self for future" post as found a few variations for part of this online but needed to pull them together.

Requirement is:

  • Ensure all HTTP requests are redirected to HTTPS
  • Handle the fact that the web server is behind a load balancer that terminates HTTPS
  • Allow for local HTTP requests via a custom port
        <rule name="Redirect to https" enabled="true" stopProcessing="true">
          <match url="^(.*)$" />
            <add input="{HTTP_X_FORWARDED_PROTO}" pattern="https" negate="true" />
            <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
         <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />

Put your ads here, just $200 per month.