Related Tags:
Asp.Net It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services. It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages (ASP) technology. Learn More, ASP.NET MVC The ASP.NET MVC framework is a lightweight, highly testable presentation framework that (as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based authentication. The MVC framework is defined in the System.Web.Mvc assembly. Learn More, IIS (Internet Information Services) IIS Stands for "Internet Information Services." IIS is a web server software package designed for Windows Server. It is used for hosting websites and other content on the Web. Microsoft's Internet Information Services provides a graphical user interface (GUI) for managing websites and the associated users. Learn More, IIS URL Rewrite The URL Rewrite Module is an extension software for IIS (Internet Information Services). URLs should be created so that they are easy to remember for the users and easy to find for the search engines. The URL Rewrite Module enables web administrators to develop and implement rules that assist them in this task. Learn More, web.config A configuration file (web.config) is used to manage various settings that define a website. The settings are stored in XML files that are separate from your application code. ... Generally a website contains a single Web.config file stored inside the application root directory. Learn More,

How to setup a redirect from non-www to www (http) for mvc application preferably using web.config rewrite rules?

Description:I have a website built on mvc deployed using the latest iis version, where I have URL Rewrite module installed. I have already tried some rewrite rules but found some wrong redirects so I have removed it, now need some urgent workaround as it is current affecting live site!

Posted by: | Posted on: Jan 07, 2020

1 answers



you can use following rule by replacing the "domainname" with your domain name

<rule name="Redirect to HTTP" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*"></match>
<add input="{HTTP_HOST}" pattern="^$"></add>
<add input="{HTTPS}" pattern="off"></add>
<action type="Redirect" url="{R:0}" redirectType="Temporary" appendQueryString="true"></action>

Note: Make sure during the testing phase always use redirectType="Temporary" once you have verified that everything is working fine only then you should update it to redirectType="Permanent"

Replied by: | Replied on: Jan 07, 2020