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>

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="(.*)"/>
        <add input="{HTTPS}" pattern="ON"/>
      <!-- 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"/>
| improve this answer | |
  • Your answer is for https-to-http, but the question is http-to-https. – Hello Aug 11 at 12:43
            <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="([^/:]*?):[^/]*?" />
                <action type="Redirect" url="https://{C:1}:1443/{R:0}" appendQueryString="false" />

This solved my problem.

| improve this answer | |
  • 1
    it should probably be: ([^/:]+)(:[^/]*)? since port might not always be there. – Leblanc Meneses Sep 18 '12 at 15:15
  • 1
    For any future googlers: it looks like this answer comes from this thread on the IIS forum. A complete description of the regex is given there. – Lasse Christiansen Aug 21 '14 at 21:24

Try changing this:

<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}"/>

to this:

<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}:1443/{R:1}"/>
| improve this answer | |
  • 1
    That doesn't seem to work. I wish the URL rewrite module had an easy way to see what it is changing the URL to. – Andy Arismendi Jan 19 '11 at 4:08
  • The matching and condition part work. When I hard code the value of the redirect URL it works, but I need the redirect URL to be dynamic. If a user types in http:// (server IP) it needs to redirect to https:// Same if they type in http:// server.domain.com:1000 it needs to redirect to https:// server.domain.com:1443. – Andy Arismendi Jan 19 '11 at 4:34
  • 1
    So it looks like part of the problem is that {HTTP_HOST} includes the port e.g. if I type http:// server:1000 then {HTTP_HOST} contains 'server:1000'. This doesn't seem right especially since there is a separate {SERVER_PORT} variable. – Andy Arismendi Jan 19 '11 at 4:59
  • I just checked it on my server and it is in fact redirecting to domain.com:1443 as expected.... Here is what I added to the Redirect URL: https://{HTTP_HOST}:1443/{R:1} – Dscoduc Jan 19 '11 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.