title: How to redirect www.example.com to example.com?
body: <p>My MVC4 app is hosted on Azure (shared website) and works fine at exaple.com.<br>
  I'd like to redirect www.example.com to example.com, but it reports 404 error if accessed at www.example.com.  </p>
  
  <p>What should I add and is it the proper way to solve this problem?<br>
  I don't think it's DNS problem as I have asked it on <a href="https://serverfault.com/questions/470888/azure-hosted-website-gives-404-error-when-domain-name-is-preceded-by-www">serverfault</a>.</p>
  
  <p>I have tried to redirect via Web.config:  </p>
  
  <pre><code>&lt;system.webServer&gt;
  &lt;rewrite&gt;
    &lt;rules&gt;
      &lt;clear /&gt;
      &lt;rule name="WWW Rewrite" stopProcessing="true" enabled="true"&gt;
        &lt;match url=".*" /&gt;
        &lt;conditions&gt;
          &lt;add input="{HTTP_HOST}" pattern="^www[.](.+)" /&gt;
        &lt;/conditions&gt;
        &lt;action type="Redirect" url="http://{C:1}/{R:0}" redirectType="Permanent" /&gt;
      &lt;/rule&gt;
    &lt;/rules&gt;
  &lt;/rewrite&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>But it doesn't work.   </p>