The best VPN 2022

The Best VPS 2022

The Best C# Book

How to configure http to automatically redirect https in IIS

How to configure HTTP to automatically redirect HTTPS in IIS? Now, most websites use HTTPS, so how does IIS configure http to automatically redirect https in IIS? This article will share the automatic redirection of HTTP requests to HTTPS through URL Write, see the content of the article for details.

Today, there are still many projects or web products developed using Microsoft’s technology stack, namely asp.net webform, asp.net core, asp.net MVC, and other technologies. Of course, most of the development languages ​​are C#, frameworks, or platforms. Naturally, it is based on the latest .net 6 or .net framework. After the development is completed, it is deployed to the production environment for customers, generally using IIS as the webserver.

Of course, it can also be deployed to the Linux system across platforms. Deploying to the Linux system needs to be handled according to the situation. If the web project developed based on the .net framework is deployed to the Linux system, there is no problem at all. jhrs.com previously published an article “Old project asp.net MVC website deployment Jexus guide” is the introduction of this aspect.

If you are using a web project or interface developed by .net core, because .net core naturally supports cross-platform deployment, and it is very convenient, you can refer to “Deploying ASP.NET Core Applications on CentOS 7“, of course, use google search Click, you will find more latest .net core deployment tutorials.

Well, in order not to deviate from the theme of this article, let’s talk about how to use HTTPS to access the whole site after you deploy the web project on IIS. That is, if there is an HTTP request, it will automatically jump to HTTPS.

HTTP to automatically redirect HTTPS in IIS

To realize the automatic conversion of HTTP requests to HTTPS requests on IIS, there are many ways to achieve this function on the Internet. I only introduce the methods that have been tested and succeeded by myself. This method is URL rewriting, which needs to be implemented by installing some extensions for IIS.

It should be noted that I have not tested whether the lower version of IIS may be successful with this method, so it is recommended to ensure that this function is successfully implemented, and IIS can be upgraded to the latest.

Installing extensions for IIS is done through the web platform installation tool. By default, the web platform installation tool will be downloaded first. Double-clicking and running the tool will automatically download and install the URL rewriting tool for you, but during the installation process, you will see The direct download address of the URL rewriting tool, the download address of the URL rewriting tool is given separately below.

In fact, the web platform installation tool is just a shell that integrates all the extensions that can be installed on IIS, through which you can download all the plug-ins that can be installed on IIS.

Download and install URL Rewrite Tool

The tool is currently version 2.0, and the Microsoft official website provides a direct download address:

http://download.microsoft.com/download/1/2/8/128E2E22-C1B9-44A4-BE2A-5859ED1D4592/rewrite_amd64_zh-CN.msi

You can also download the URL Rewriting Tool from this site: IIS URL Rewriting Tool Download

The direct download is a file with MSI as the suffix extension, double-click to install it directly.

Below are some screenshots of the installation process.

How to configure http to automatically redirect https in IIS
How to configure http to automatically redirect https in IIS
How to configure http to automatically redirect https in IIS
How to configure http to automatically redirect https in IIS
How to configure http to automatically redirect https in IIS
How to configure http to automatically redirect https in IIS
How to configure http to automatically redirect https in IIS
How to configure http to automatically redirect https in IIS
How to configure http to automatically redirect https in IIS
How to configure http to automatically redirect https in IIS

URL redirection

When a visitor enters the http://znlive.com link in the browser, to automatically jump to https://znlive.com, URL redirection needs to be performed in the configuration file. Add the configuration file as follows:

<system.webServer>
    <rewrite>
      <rules>
  <clear />
        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>

Note that the clear configuration node above does not necessarily need to be added. After you configure it, redirection cannot be achieved. You can try adding the clear node.

Leave a Comment