I use a dynamic DNS service to host my DNS entries. Back when I started hosting my blog, I was using marklio.dnsalias.com instead of www.marklio.com. Since I still have that name pointed at this server, some search engines still have not let go of that old dns name. In a few months, I'm going to have to move this to a hosted environment (it's currently just running on a server at my house), at which point the two names will point to different places. I've been strategizing the move for a while now, and I've just implemented step 1, which is to ween http traffic from the old alias.
I've done that by implementing a permanent redirect for any request to the old name. I created a little IHttpModule that hooks into the BeginRequest event, and looks for the old dns name. If found, it returns the status 301 (permanent redirect), and dynamically builds the appropriate request to www.marklio.com. It seems to work well. Hopefully the search engines will handle this appropriately.
For any interested, here's the relevant code:
public class RedirectModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
//do nothing
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
#endregion
void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
Uri url = context.Request.Url;
if (url.Host == "marklio.dnsalias.com")
{
context.Response.AddHeader("Location",
url.ToString().Replace("marklio.dnsalias.com", "www.marklio.com"));
context.Response.StatusCode = 301;
context.Response.End();
}
}
The whole pluggable nature of ASP.net is really sweet, although this really got me wishing there was a way to "script" this class rather than have to build it and add it to the web.config.