Redirect naked domain to www. and https in MVC Core

 Author: Shengtao Zhou       Created: 3/26/2019 10:36:12 PM       Modified: 3/26/2019 10:52:12 PM   More...
There're 4 website URL variations: (naked domain)

Ideally, when user access any of these URLs, the requests should be redirect to

This can be split to 2 tasks: Redirect to https and Redirect to Let's resolve it step by step.

1. Redirect to https

Make 2 change in Startup.cs file:

1) Add redirect to Configure method

2) Add https port number to ConfigureServices method
services.AddHttpsRedirection(options =>
        options.HttpsPort = 443;

2. Redirect to

1) Open URL Rewrite in IIS Manager

If you don't have URL Rewrite, please download and install from here,

2) Add Canonical domain name

Click "Add Rules", then click "Add Canonical domain name".

3) Save the rule

Enter, click Save. The change will be save to web.config file. You may want to save the change to your server environment.

3. Verify the setting

If you accessed in the past, the SSL certificate will be cached in the browser. So even the https redirect isn't set properly, you won't be able to see the issue unless clear the browser cache first. A better way to test is using Chrome incognito mode, or private mode.

More...          Back to List          

(Please enter you comments between 100 to 2000 characters. Thanks for your contribution.) 

         Created:       Modified: 

Editing a comment

       (Please enter you comments between 100 to 2000 characters. Please login before edit comment.) 

div class="col-md-2">