IIS URL Rewrite HTTP to HTTPS with Port
My website has two bindings: 1000 and 1443 (port 80/443 are in use by another website on the same IIS instance). Port 1000 is HTTP, port 1443 is HTTPS. What I want to do is redirect any incoming request using "htt p://server:1000" to "https://server:1443"
. I'm playing around with IIS 7 rewrite module 2.0 but I'm banging my head against the wall. Any insight is appreciated!
BTW the rewrite configuration below works great with a site that has an HTTP binding on port 80 and HTTPS binding on port 443, but it doesn't work with my ports.
P.S. My URLs intentionally have spaces because the 'spam prevention mechanism' kicked in. For some reason google login doesn't work anymore so I had to create an OpenID account (No Script could be the culprit). I'm not sure how to get XML to display nicely so I added spaces after the opening brackets.
< ?xml version="1.0" encoding="utf-8"?>
< configuration>
< system.webServer>
< rewrite>
< rules>
< rule name="HTTP to HTTPS redirect" stopProcessing="true">
< match url="(.*)" />
< conditions trackAllCaptures="true">
< add input="{HTTPS}" pattern="off" />
< /conditions>
< action type="Redirect" redirectType="Found" url="htt ps: // {HTTP_HOST}/{R:1}" />
< /rule>
< /rules>
< /rewrite>
< /system.webServer>
< /configuration>
Solution 1:
Even though the question was answered awhile ago, this is the rule that I used.
<rule name="Redirect to HTTP on different port" enabled="true" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="ON"/>
</conditions>
<!-- Cannot Use {HTTP_HOST} as it contains both the {SERVER_NAME}{SERVER_PORT} -->
<action type="Redirect" url="http://{SERVER_NAME}:1000{HTTP_URL}" redirectType="Found" appendQueryString="false"/>
</rule>
Solution 2:
<rule name="HTTP to HTTPS on different SSL Port" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?" />
</conditions>
<action type="Redirect" url="https://{C:1}:1443/{R:0}" appendQueryString="false" />
</rule>
This solved my problem.