简体   繁体   中英

HTTP to HTTPS Redirect in IIS

I have to redirect my site from http to https, whenever any user open my site using http.

For example: -

http:\\\\abc.mywebsite.com should go to https:\\\\abc.mywebsite.com

Notice that in above URL, it is not www.mywebsite.com, instead it is custom URL as abc.mywebsite.com.

I have tried URL Rewrite tool and followed all steps mentioned here . However, I cannot get URL Rewrite to work properly to redirect.

Here is the URL Redirect rule looks like in IIS: -

在此处输入图片说明

Here is how my web.config looks like after adding rule using URL Rewrite.

 <configuration> ..... ..... ..... <system.webServer> ..... ..... ..... <rewrite> <rules> <rule name="Http to Https" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> ..... ..... ..... </configuration> 

I have also uncheck Require SSL check box under SSL Settings.

However, after doing all this, my website is still not redirecting to https. Just giving error "...can't reach this page".

Please suggest if I am missing anything here.

I have some doubts about the rewrite rules because I see many examples that are different.

Trying different values like the one from this Microsoft Blog could yield better results:

<rewrite>
    <rules>
        <rule name="Redirect to http" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
            <match url="*" negate="false" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTPS}" pattern="off" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
        </rule>
    </rules>
</rewrite>

You can also setup Tracing for Failed Requests in IIS 7 . This could give you insight into why it's failing to redirect.

I was facing same issue within the same site when trying to redirect from http to https. I did created new site and added the binding as http://www.example.com/ And then I have created new Http Redirect and added my https://www.example.com/ it worked.

Make sure that you have setup the bindings correctly in IIS, the second line highlighted in red should be there.

  1. Type = HTTPS
  2. Host Name = the site address like "site.domain.com"
  3. Port = 443
  4. IP Address = The IP Address of the server you are trying to access.

IIS绑定

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