301 redirect using web.config
To do 301 permanent redirect add following line of codes in web.config.
<configuration>
<system .webserver>
<rewrite>
<rules>
<rule name="Redirect domain.com to www" patternsyntax="Wildcard" stopprocessing="true">
<match url="*">
<conditions>
<add input="{HTTP_HOST}" pattern="yourdomain.com">
</add></conditions>
<action type="Redirect" url="http://www.yourdomain.com/{R:0}">
</action></match></rule>
</rules>
</rewrite>
</system .webserver>
</configuration>
Read more...
<configuration>
<system .webserver>
<rewrite>
<rules>
<rule name="Redirect domain.com to www" patternsyntax="Wildcard" stopprocessing="true">
<match url="*">
<conditions>
<add input="{HTTP_HOST}" pattern="yourdomain.com">
</add></conditions>
<action type="Redirect" url="http://www.yourdomain.com/{R:0}">
</action></match></rule>
</rules>
</rewrite>
</system .webserver>
</configuration>