redirect non www to www in iis 7 and 8


In this article we will explain how to redirect non www to www by using IIS 7 and IIS 8 with example.


The common use of URL Rewrite is redirecting to Many people are doing this for search engine optimization (SEO) so that search engines only see the one site, rather than two sites. The goal is to set a permanent 301 redirect.

Let’s get started. First, open IIS Manager and select your website and double-click on the “URL Rewrite” icon.

Next, click on “Add Rules…” from the Actions pane.

Now select blank rule from wizard options and click ok button.

redirect non www to www in iis 7 and 8

Now Give your rule “Name”. I’ll call mine “non www to www”.

In the “Using” dropdown box you can choose between Matches the Pattern and Wildcards.

Enter * for the “Pattern”. That means anything qualifies. We’ll use a condition later instead of matching to the URL. (for Matches the Pattern, use .*).

redirect non www to www in iis 7 and 8

Now expand the “Conditions” section and click “Add.

redirect non www to www in iis 7 and 8

”. In the “Add Condition” dialogue enter the following details and Click OK.

redirect non www to www in iis 7 and 8

Finally, it’s time to set the Action.

In the Action section make sure that the “Action Type” is set to Redirect.

For the “Action Properties”, enter{R:0}. The {R:0} retains the existing URL so if someone typed something like it would retain the contactus as it adds the www.

redirect non www to www in iis 7 and 8 

Finally, Apply the rule and test!

Using a Text Editor

You can also create this rule manually by adding the following to your site’s web.config.

In the <system.webServer> section of your web.config, add the following:



        <rule name='Redirect to www' patternSyntax='Wildcard' stopProcessing='true'>
            <match url='*' />
                <add input='{HTTP_HOST}' pattern='' />
            <action type='Redirect' url='{R:0}' />

This is just the start to great SEO, but it’s a common step and one that I hope you find helpful.

Last updated:9/7/2019 12:18:18 AM
Aditya Patel

Aditya Patel

Hi, I am a Senior Software Developer in MindStick Software pvt. Ltd. I have done BCA from dr. c.v. Raman university. I have more than five years experience in Microsoft Technology MVC 4, MVC Core, C#,Vb.Net, rdlc Reporting ,SQL Server and other jQuery, css, Bootstrap, Knockout.js, angular.js,react.js Html, Crystal Reporting etc.


Leave Comment