IIS7/8 URL Rewrite ? rewriting non-www to www

In order to Redirect non-www to www on your website, manually edit the web.config file of site and add the following rewrite rule:

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

Leave a Reply

Your email address will not be published.