I modified .Text (Dot Text) so that all requests to SuperJason.com would be permanently redirected to www.SuperJason.com. This is very important, because Google see’s links to SuperJason.com and www.SuperJason.com as different sites. That causes your PageRank to be spread between multiple pages.
protected void Application_BeginRequest(Object sender, EventArgs e) { string currUrl; string redirUrl; if(Request.Url != null) { currUrl = Request.Url.ToString(); if(currUrl.ToUpper().StartsWith("http://SuperJason.com".ToUpper())) { redirUrl = "http://www.SuperJason.com" + currUrl.Substring("http://SuperJason.com".Length); Response.Status = "301 Moved Permanently"; Response.AddHeader("Location", redirUrl); } } }
When I made that change and uploaded it, it broke my site! So I took a look at the application level error handling, and noticed that it treats all exceptions as fatal, even though that is not the case. When you redirect, it throws a ThreadAbortException. So I had to change the error handling to ignore this error:
protected void Application_Error(Object sender, EventArgs e) { if (Context != null && Context.IsCustomErrorEnabled) { if(Context.Error.GetType() == typeof(System.Threading.ThreadAbortException)) return; else Server.Transfer(ERROR_PAGE_LOCATION, false); } }
After making that change it appeared to work. To double check, I used the LiveHttpHeaders extension for Firefox. Looking through the headers proved that I was sending a 301 redirect to the browser.