IIS 7 Url Rewrite for only port 80

5,450

I just turned off this same rule for a specific port using a negated condition on the SERVER_PORT variable (docs). For port XXXX:

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      <add input="{SERVER_PORT}" pattern="XXXX" negate="true" />
    </conditions>
  <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
Share:
5,450

Related videos on Youtube

Josh
Author by

Josh

A man, when confronted with a problem, said "I know! I'll use regular expressions!" Now he has two problems.

Updated on September 18, 2022

Comments

  • Josh
    Josh over 1 year

    I have a site where any traffic coming in on port 80 needs to be redirected to port 443 (https). According to this article, that is easy enough and it works. My problem is, however, that this is a load balanced environment. I want to open up a non standard port behind my firewall so that when my sever is off the load balancer I can push my code and test it using http://myip:XXXX via http on the non-standard port without it forcing https.

    The rule used in the article is this

    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
      <match url="(.*)" />
        <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
    

    How can I tweak this so it only redirects for port 80 (or doesn't redirect for my test port)?