If you would like to do a domain URL redirection from domain.com to www.domain.com or vise versa, you can do something like this:

Place either of these (depending on what you’d like done. And edit to match your domain) inside the <system.webServer></system.webServer> tags in the web.config of the domain.

<rewrite><rules>
<rule name=”Add WWW prefix” >
  <match url=”(.*)” ignoreCase=”true” />
    <conditions>
      <add input=”{HTTP_HOST}” pattern=”^domain\.com” />
    </conditions>
  <action type=”Redirect” url=”http://www.domain.com/{R:1}”
    redirectType=”Permanent” />
</rule>

<rule name=”Remove WWW prefix” >
  <match url=”(.*)” ignoreCase=”true” />
    <conditions>
      <add input=”{HTTP_HOST}” pattern=”^www\.domain\.com” />
    </conditions>
  <action type=”Redirect” url=”http://domain.com/{R:1}”
    redirectType=”Permanent” />
</rule>
</rules></rewrite>

Was this answer helpful? 332 Users Found This Useful (332 Votes)