301 Redirects For SEO And PageRank!
(Sep 01 2007 - 07:51:58 PM
by Timothy Khouri
) - [print blog
The company that I work for has hired a consulting agency to review our public website and make suggestions for search engine optimization (SEO) and other things. Since I've been in the web marketing field in a previous job, I already have a strong grasp of a lot of the key concepts. But one of the suggestions that they made was something that I didn't know how to do with ASP.NET until now.
301 Redirects in ASP.NET
A "301 redirect" tells browsers and search engines that a resource has been PERMANENTLY moved to another location. This is useful in domain canonicalization (which is a big word that basically means "www" and "non-www" are counted together). So here's the code that I added in my Global.asax file for SingingEels that will ensure that "singingeels.com" will redirect to "www.singingeels.com" as I want it to. Not only will it redirect, but it will add the appropriate "301" header which will tell Google, Yahoo, MSN, ASK.com (and any other search engine) to credit any links or info that they have to the main URL.
Here's how I did it in C# in my Global.asax file:
void Application_BeginRequest(object sender, EventArgs e)
if (this.Request.Url.Host == "singingeels.com")
UriBuilder redirectToBuilder = new UriBuilder(this.Request.Url);
redirectToBuilder.Host = "www.singingeels.com";
this.Response.Status = "301 Moved Permanently";
I intentionally do not do a "Response.End" after that in case the browser or search engine doesn't know how to do the redirect. But what this does is it makes it so ANY request that comes to my application under the "singingeels.com" domain will be moved to "www.singingeels.com". I also intentionally chose to only redirect that one domain for now.