3

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)?

Josh
  • 205

2 Answers2

2

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>
Ian G
  • 255
0

The web.config file is site-centric (or rather, directory-centric, to the directory it's sitting in), regardless of which port you hit it on.

The trick (and I've never done this in regards to ports) is going to be to change your URL match rule to match URL requests that end in :80. My initial guess would be that changing it to (.*:80) might just work.