1
votes

I setup IIS to redirect non https traffic to https by using the rewrite wizzard in IIS. I followed the steps outlined here: https://www.namecheap.com/support/knowledgebase/article.aspx/9953/38/iis-redirect-http-to-https.

Now I'm wanting to add a condition to say if the {server_port} = 80.

I added a new condition:
Condition Input: {Server_Port}
Check if input string: matches the pattern
pattern: 80

Under conditions : Logical Grouping: match all

I then saved the rule and restarted IIS.

I'm still getting all traffic to my site redirected to https which tosses Error code: SSL_ERROR_RX_RECORD_TOO_LONG since https:// www.mysite.com:83 does not compute.

How do I write the condition to redirect only if the server port is 80?

Please be aware that I have not written my redirect in the web.config and am asking because most of the examples I've found discuss web.config. I did find a web config example that should work, but I can't figure out how to use the rewrite tool to implement this:

<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>
1
That doesn't help. I already know that my rewrite isn't configured correctly. I'm asking for help making it correct. Using your link only shows me that it's not working properly. And it's relying on web.config. I'm trying to use the rewrite module in IIS. I need help rewriting only port 80. right now it's redirecting all non https requests to https.RCDAWebmaster
FRT should also show you the various characteristics of the incoming requests to help you write better rules, so I wonder why you said that does not help.Lex Li

1 Answers

1
votes

I found simple mistake in your rule condition is <add input="{SERVER_PORT}" pattern="XXXX" negate="true" /> negate="true" means it does not match pattern and it rediect to the https. to impemnet your requiremnet you could use bwlow rule:

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