How to configure an automatic redirection from HTTP to HTTPS

To configure forced site redirection from HTTP to HTTPS protocol, add rules for the URLRewrite module, which is enabled by default in the IIS server configuration, in the <system.webServer> section in the web.config file.

The section in the web.config file should look something like this:

<?xml version="1.0" encoding="UTF-8"?>
                <clear />
                <rule name="Redirect to https" stopProcessing="true">
                    <match url=".*" />
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />