IIS http redirection to HTTPS

Source: Internet
Author: User

Recently customer a website upgrade to HTTPS protocol access, but for user input, customer requirements when the user entered the HTTP protocol, can automatically direct to HTTPS, similar to Baidu website, when you enter www.baidu.com and enter, the address bar automatically become https://www.baidu.com.

The previous steps briefly describe how to implement this feature.

1) Download and install the Microsoft URL Rewrite module

https://www.microsoft.com/zh-CN/download/details.aspx?id=7435

Note: Depending on the system, different languages are selected.

My machine is in English, so the following basic is English.

2) The site binds to the following two types of protocols:

Note: The default HTTPS port number is 443 because my native port has been exploited, so this is a 449 demo.

3) The SSL setting of the site, make sure "Require SSL" is not selected.

3) In the case of an ASP. NET site, add the following configuration section directly in the Web. config file, and place it as a child of <configuration> at the end of the file.

<system.webServer>
<rewrite>
<rules>
<rule name= "Redirect to HTTPS" stopprocessing= "true" >
<match url= "(. *)"/>
<conditions>
<add input= "{HTTPS}" pattern= "^off$"/>
<add input= "{https_host}" pattern= "^ (localhost)" negate= "true"/>
</conditions>
<action type= "Redirect" url= "Https://{http_host}:449/{r:1}"Redirecttype=" Seeother "/>
</rule>
</rules>
</rewrite>
</system.webServer>

Note: When you use the default HTTPS port, the above port number 449 is not required, directly to https://{http_host}/{r:1}

The above configuration can also be manually added directly in the URL write in IIS, which is done roughly as follows:

Web. config configuration:

<?xml version="1.0"encoding="Utf-8"?><!--For more information about how to configure an ASP. NET application, go to http://go.microsoft.com/fwlink/?linkid=169433--><configuration> <system.web> <compilation debug="true"targetframework="4.5"/> "4.5"/> </system.web><system.webServer> <rewrite> <rules> <ru Le Name="Redirect to HTTPS"stopprocessing="true"> <match url="(.*)"/> <conditions> <add input="{HTTPS}"pattern="^off$"/> <add input="{Https_host}"pattern="^ (localhost)"Negate="true"/> </conditions> <action type="Redirect"Url="Https://{http_host}:449/{r:1}"Redirecttype="Seeother"/> </rule> </rules> </rewrite> </system.webserver></conf Iguration>

IIS http redirection to HTTPS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.