简体   繁体   English

IIS中的HTTP到HTTPS重定向

[英]HTTP to HTTPS Redirect in IIS

I have to redirect my site from http to https, whenever any user open my site using http. 每当任何用户使用http打开我的网站时,我都必须将我的网站从http重定向到https。

For example: - 例如: -

http:\\\\abc.mywebsite.com should go to https:\\\\abc.mywebsite.com http:\\\\ abc.mywebsite.com应该转到https:\\\\ abc.mywebsite.com

Notice that in above URL, it is not www.mywebsite.com, instead it is custom URL as abc.mywebsite.com. 请注意,在上述URL中,它不是www.mywebsite.com,而是自定义URL,为abc.mywebsite.com。

I have tried URL Rewrite tool and followed all steps mentioned here . 我尝试了URL重写工具,并遵循了此处提到的所有步骤。 However, I cannot get URL Rewrite to work properly to redirect. 但是,我无法使URL Rewrite正常工作以进行重定向。

Here is the URL Redirect rule looks like in IIS: - 以下是IIS中的URL重定向规则:-

在此处输入图片说明

Here is how my web.config looks like after adding rule using URL Rewrite. 这是使用URL重写添加规则后的web.config外观。

 <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. 我还取消选中了“ SSL设置”下的“需要SSL”复选框。

However, after doing all this, my website is still not redirecting to https. 但是,完成所有这些操作后,我的网站仍然没有重定向到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: 尝试使用此Microsoft博客中的值之类的其他值可能会产生更好的结果:

<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 . 您也可以在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. 尝试从http重定向到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. 我确实创建了新站点,并将绑定添加为http://www.example.com/ ,然后创建了新的Http Redirect并添加了我的https://www.example.com/

Make sure that you have setup the bindings correctly in IIS, the second line highlighted in red should be there. 确保已在IIS中正确设置了绑定,第二行以红色突出显示。

  1. Type = HTTPS 类型= HTTPS
  2. Host Name = the site address like "site.domain.com" 主机名=网站地址,例如“ site.domain.com”
  3. Port = 443 端口= 443
  4. IP Address = The IP Address of the server you are trying to access. IP地址=您尝试访问的服务器的IP地址。

IIS绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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