Force https with URL rewrite

For most sites, after installing a SSL certificate, https can be forced by adding a URL rewrite rule to the site's web.config file.  Though, please note it will not apply to all sites, for example it may not work for those using routing or it may conflict with any existing URL rewrite rules.  In the case of a CMS like WordPress or nopCommerce, it is often a setting within the CMS itself.  The URL rewrite rule also will not work for ASP.NET Core sites (see below).
 
 
URL rewrite rule to redirect all requests to https
 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to https" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
 
 
Rewrite in ASP.NET Core to redirect all requests to https
 
To use rewrite rules in an ASP.NET Core application, first download the Microsoft.AspNetCore.Rewrite library through NuGet.  In Visual Studio, Tools > NuGet Package Manager > Manage NuGet Packages for Solution... and in the search field under Browse enter Microsoft.AspNetCore.Rewrite.  Highlight the package, click the checkbox next to your Project and Install.
 
Startup.cs
 
Open the Startup.cs file and to the top of the file add:
 
using Microsoft.AspNetCore.Rewrite;
 
Then add the following to the Configure method:
 
app.UseRewriter(new RewriteOptions()
	.AddRedirectToHttps()
	);