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>
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.