In the <system.webServer> section of your web.config, add the following:

  • Wildcards

  • Regular Expressions


  1. Wildcards

<rewrite>

  <rules>

      <rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">

          <match url="*" />

          <conditions>

              <add input="{HTTP_HOST}" pattern="domain.com" />

          </conditions>

          <action type="Redirect" url="http://www.domain.com/{R:0}" />

      </rule>

  </rules>

</rewrite>


  1. Regular Expressions

<rewrite>

  <rules>

      <rule name="Redirect domain.com to www" patternSyntax="ECMAScript" stopProcessing="true">

          <match url=".*" />

          <conditions>

              <add input="{HTTP_HOST}" pattern="^domain.com$" />

          </conditions>

          <action type="Redirect" url="http://www.domain.com/{R:0}" />

      </rule>

  </rules>

</rewrite>