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>
  • Curious why one would not redirectType="Permanent" in this rule?
    – qxotk
    Dec 20, 2022 at 14:34

3 Answers 3


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"/>
  • Your answer is for https-to-http, but the question is http-to-https.
    – Hello
    Aug 11, 2020 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.

  • 2
    it should probably be: ([^/:]+)(:[^/]*)? since port might not always be there. Sep 18, 2012 at 15:15
  • 2
    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. Aug 21, 2014 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}"/>
  • 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. Jan 19, 2011 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. Jan 19, 2011 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. Jan 19, 2011 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, 2011 at 23:47
  • The main problem is the variable {HTTP_HOST} which already contains the PORT information. Apr 6, 2022 at 10:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .