Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 "htt ps://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>

share|improve this question
add comment

3 Answers

            <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.

share|improve this answer
    
it should probably be: ([^/:]+)(:[^/]*)? since port might not always be there. –  Leblanc Meneses Sep 18 '12 at 15:15
add comment

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>
share|improve this answer
add comment

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}"/>
share|improve this answer
    
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:// 10.0.0.100:1000 (server IP) it needs to redirect to https:// 10.0.0.100:1443. 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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