简体   繁体   中英

Simple IIS rewrite

This has been asked a few times, but it doesn't seem to work for me. I want to redirect a url like http://11.11.11.11:8008/foo/bar?baz=1 to be https://11.11.11.11:1443/foo/bar?baz=1 . Just add the S and change the port.

If a user types out computername.domain.local or I browse with localhost , nothing should happen. It should only ever redirect for a specific IP address/port and only when accessed via http.

The reason is that my machine uses 443 for SSL internally ( localhost or computername.domain.local ). But for requests that originate outside my office building, we have a router redirection. So they access a public IP address with a port and SSL is no longer on 443. Therefore to test code on tablets and from other locations I need to browse to an IP address with a port.

How about this?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^11\.11\.11\.11$
RewriteCond %{SERVER_PORT} 8008
RewriteRule ^(.*)$ https://11.11.11.11:1443/$1 [R]

So this was two misunderstandings on my part. First off, external traffic from outside my company uses a company specific IP address and port 8008. This gets them routed to my actual computer which hosts my site. But, when the traffic comes through it's directed to port 80 on my machine, NOT 8008. Secondly, the URL expression in the rewrite only includes the path and query string. You can't match the full URL in there as I was trying to do.

The solution was to add a wild card to the matching, and use conditions to hit everything else needed.

<rule name="SSL on 1443" stopProcessing="true">
    <match url="(.*)" />
    <action type="Redirect" url="https://11.11.11.11:1443/{R:0}" redirectType="Found" />
    <conditions>
        <add input="{HTTPS}" pattern="OFF" />
        <add input="{HTTP_HOST}" pattern="11\.11\.11\.11" />
    </conditions>
</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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM