title: asp.net MVC: How to redirect a non www to www and vice versa
body: <p>I would like to redirect all www traffic to non-www traffic</p>
  <p>I have copied this into my <code>web.config</code></p>
  <pre><code>&lt;system.webServer&gt; / &lt;rewrite&gt; / &lt;rules&gt;
  
  &lt;rule name=&quot;Remove WWW prefix&quot; &gt;
  &lt;match url=&quot;(.*)&quot; ignoreCase=&quot;true&quot; /&gt;
  &lt;conditions&gt;
  &lt;add input=&quot;{HTTP_HOST}&quot; pattern=&quot;^www\.example\.com&quot; /&gt;
  &lt;/conditions&gt;
  &lt;action type=&quot;Redirect&quot; url=&quot;http://example.com/{R:1}&quot;
      redirectType=&quot;Permanent&quot; /&gt;
  &lt;/rule&gt;
  </code></pre>
  <p>per this post</p>
  <blockquote>
  <p><a href="https://stackoverflow.com/questions/521804/how-to-redirect-with-www-urls-to-without-www-urls-or-vice-versa/521811#521811">How to redirect with &quot;www&quot; URL&#39;s to without &quot;www&quot; URL&#39;s or vice-versa?</a></p>
  </blockquote>
  <p>but I got a 500 internal server error.</p>