Google Optimization Tools and Permanent Redirects
Date Published: 17 January 2006
A recent forum thread on AspAdvice.com dealt with this issue. It’s far better to use 301 redirects than 302 redirects within your applications if the page in question is permanently at the new location. One example of this would be when handling site moves from an old architecture to a new architecture — you want to avoid tons of 404 errors and keep you search indexes, so you redirect users looking for the old URL to the new one. Works great, but if you use Response.Redirect, it’s sending a 302 (Found / Moved Temporarily) code, which is not what you want. Instead, you want to use a 301 Moved Permanently code, along with the new location.
Unfortunately, there is no built in way to do this with a single line of code in ASP.NET. I wrote one up a while back that looks like this — feel free to use it:
public abstract class Utility
public static void Redirect301(string url)
public static void Redirect301(string url, bool endResponse)
System.Web.HttpContext context = System.Web.HttpContext.Current;
if(context != null)
context.Response.Status = “301 Moved Permanently”;
Another important consideration here is the use of “www.” in URLs. A lot of people still type in “www.” as a force of habit. However, these four characters are largely obsolete today. With very few exceptions, websites today do not require any “www.” prefix, and most sites advertise without them (notice on TV that commercials end with nfl.com or aol.com, or moviename.com, not www DOT anything). Having a site that works equally well with and without WWW as a subdomain (or perhaps with anything as a subdomain — it’s not difficult to map [anything].domain.com to one web server) is pretty much standard today, but it can present a problem with URL Canonicalization. If both www.aspalliance.com and aspalliance.com refer to the same content, it can result in duplicate entries in the search engine’s index. The solution is to use 301 redirects from one address to the other. Personally I prefer the shorter URL to the archaic www URL, so I would create a 301 redirect from www.aspalliance.com to aspalliance.com. This can easily be done in ASP.NET in the BeginRequest method, or through some third party tools such as ISAPIRewrite.
Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.