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, SSL certificate An SSL certificate is a digital certificate that authenticates a website's identity and enables an encrypted connection. SSL stands for Secure Sockets Layer, a security protocol that creates an encrypted link between a web server and a web browser. Learn More,

IIS URL Rewrite rule for redirect http to https and non-www to www using web.config?

Description:Basically I need two separate IIS URL Rewrite rule for my website, one for redirecting visitors from http to https and the other one for redirecting visitors from non-www to www using web.config
Previously I was using the solution which was for working fine for me with http but now I have setup the ssl so now I have tried updating the same code but I am having issues with it.

Posted by: | Posted on: Apr 01, 2022

1 answers

Replies

3

You can use the following URL rewrite rules as per your requirement
1) For Redirect from http to https you can use following url rewrite rule

<rule name="RedirectFromHTTPToHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="Temporary" />
</rule>

2) For Redirect from non-www to www you can use following url rewrite rule

<rule name="RedirectNonWwwToWww" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" redirectType="Temporary" />
</rule>

Note: Make sure during the verification 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: Apr 04, 2022



Reply
×

Preview