URL Rewrite Sample to Add www to the URL

Here is a sample web.config file to redirect any requests to http://site.com to http://www.site.com.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Add www" patternSyntax="Wildcard" stopProcessing="true">
                    <match url="*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="www.site.com" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://www.site.com/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

No Comments