IIS7 URL Rewrite - Add "www" prefix

Viewed 39679

How to force example.com to be redirected to www.example.com with URL rewriting in IIS7? What kind of rule should go into the web.config? Thanks.

4 Answers

Not sure about the best possible way to do this, but I have a site with all old domains / subdomains running this web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Transfer" stopProcessing="true">
                    <match url=".*" />
                    <action type="Redirect" url="http://www.targetsite.com/{R:0}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Seems to get the job done.

Related