title: Redirecting www.xxx.yyy.com to xxx.yyy.com
body: <p>It seems, that I'm unable to redirect my webpage from WWW to non-WWW variant.
  At first I tried to do this by using IIS rewrite module like this:</p>
  
  <pre><code>&lt;rewrite&gt;
        &lt;rules&gt;
          &lt;rule name="Canonical" stopProcessing="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;
  </code></pre>
  
  <p>But it keeps me redirecting from <strong>www.xxx.yyy.com</strong> to <strong>www.yyy.com/xxx</strong> which is not i want to do.</p>
  
  <p>Next solution I've tried, was to do it in <strong>Global.asax</strong> file in <em>Application_BeginRequest</em> methods like this:</p>
  
  <pre><code>protected void Application_BeginRequest(object sender, EventArgs ev)
  {
      if (Request.Url.Host.StartsWith("www", StringComparison.InvariantCultureIgnoreCase))
      {
          Response.Clear();
          Response.AddHeader("Location", 
              String.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host.Substring(4), Request.Url.PathAndQuery)
              );
          Response.StatusCode = 301;
          Response.End();
      }
  }
  </code></pre>
  
  <p>but this time it keeps saying that there is a redirect loop.
  Thanks for help in advance :)</p>