redirect non www to www in iis 7 and 8

Introduction:

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

Description:

The common use of URL Rewrite is redirecting http://domain.com to http://www.domain.com. 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 http://www.domain.com/{R:0}. The {R:0} retains the existing URL so if someone typed something like http://domain.com/contactus 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:

Wildcards

<rewrite>

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

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.

0 Comments

Leave Comment