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:
<rewrite>
<rules>
<rule name="Canonical" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www[.](.+)" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
But it keeps me redirecting from www.xxx.yyy.com to www.yyy.com/xxx which is not i want to do.
Next solution I've tried, was to do it in Global.asax file in Application_BeginRequest methods like this:
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();
}
}
but this time it keeps saying that there is a redirect loop. Thanks for help in advance :)