There are situations when you wish to redirect every request to HTTP with www or non-www version of your website to a URL containing HTTPS and www. This has become important from an SEO perspective because search engines treat HTTP and HTTPS versions of your website as two different websites with exactly the same content. You probably also know that this is a huge problem and your website might even get penalized for this. To overcome this problem, you need to implement 301 redirects on your website.

The process of implementing a 301 redirect depends on the platform you are using. In this article, I am going to show you how to redirect HTTP www and non-www to HTTPS www on IIS using web.config file.

How to Implement HTTPS www Redirects on IIS

Open up the web.config file of your website in your favorite text-editor or IDE, which must be Microsoft Visual Studio if you are working in ASP.NET. The code to implement 301 redirects goes inside the section as shown below:


    
        
            
                
                
                    
                    
                        
                    
                    
                
                
                    
                    
                        
                    
                    
                
            
        
    

Don't forget to replace domainname.com with your actual domain name. This is a perfectly tested code snippet that I've used on tens of websites. If you face any trouble while implementing 301 redirects on your website, let me know in the comments section.