title: asp.net redirect non www link to www
body: <p>I have a classic asp.net site running on IIS 7.5. I added th following rewrite to the web config file for redirecting non www link to www</p>
  
  <pre><code> &lt;?xml version="1.0"?&gt;
      &lt;configuration&gt;
          &lt;system.web&gt;
            &lt;customErrors mode="RemoteOnly" defaultRedirect="/404.html"&gt;
              &lt;error statusCode="404" redirect="/404.html" /&gt;
            &lt;/customErrors&gt;
          &lt;/system.web&gt;
          &lt;system.webServer&gt;
            &lt;httpErrors&gt;
              &lt;clear /&gt;
              &lt;error statusCode="404" subStatusCode="-1" path="/404.html" responseMode="ExecuteURL" /&gt;
            &lt;/httpErrors&gt;
  
  &lt;!-- code added --&gt;
            &lt;rewrite&gt;
              &lt;rules&gt;
                &lt;rule name="Redirect" patternSyntax="ECMAScript" stopProcessing="true"&gt;
                 &lt;match url=".*" /&gt;
                 &lt;conditions&gt;
                  &lt;add input="{HTTP_HOST}" pattern="^domain.com$" /&gt;
                 &lt;/conditions&gt;
                 &lt;action type="Redirect" url="http://www.domain.com/{R:0}" /&gt;
               &lt;/rule&gt;
             &lt;/rules&gt;
           &lt;/rewrite&gt;
  &lt;!-- code added --&gt;
         &lt;/system.webServer&gt;
      &lt;/configuration&gt;
  </code></pre>
  
  <p>Yes the rewrite mod was not enabled, it works now.</p>