Forum Moderators: open
[edited by: Ocean10000 at 7:37 pm (utc) on Mar 6, 2011]
[edit reason] Switched to "example.com" Domain [/edit]
public class Global:System.Web.HttpApplication
{
protected void Application_BeginRequest(object sender, EventArgs e)
{
string host = this.Request.Url.Host.ToLower();
if (host == "example.com")
{
host = "www.example.com";
host = this.Request.Url.AbsoluteUri.Replace("example.com", host);
}
else
{
host = this.Request.Url.AbsoluteUri;
}
if (host != this.Request.Url.AbsoluteUri)
{
this.Response.Status = "301 Moved Permanently";
this.Response.AppendHeader("Location", host);
this.Response.End();
return;
}
}
}
If you have access to IIS manager you can just add another domain record (example.com instead of www.example.com) and redirect it permanently to the www record.
If you have access to IIS manager you can just add another domain record (example.com instead of www.example.com) and redirect it permanently to the www record.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect example.com to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="example.com" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>