Tuesday, February 01, 2005

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.

posted on Tuesday, February 01, 2005 6:29:04 PM (Pacific Standard Time, UTC-08:00)  #    Comments [2]
Related posts:
LinqToStdf now on CodePlex
Image Slicer for Deep Zoom in Silverlight 2
Silverlight limitations and Constrained Callvirt in IL
What are the generic Delegates in the framework for?
What is System.__Canon and why is it on my stack?
Adding support for .ashx-based views in ASP.net MVC
Tracked by:
"New Host" (marklio) [Trackback]
"Scriptable IHttpModule" (marklio) [Trackback]
"bontril prescription diet pill" (bontril prescription diet pill) [Trackback]
"used car buying guide quebec" (used car buying guide quebec) [Trackback]
"bone jewellery" (bone jewellery) [Trackback]
"star furniture" (star furniture) [Trackback]
"on off on round rocker switch" (on off on round rocker switch) [Trackback]
"Cheddars Restaurant in Texas" (Cheddars Restaurant in Texas) [Trackback]
"pictures of space" (pictures of space) [Trackback]
"Cancun Women" (Cancun Women) [Trackback]
"money money health health go2clickbank.com" (money money health health go2click... [Trackback]
"1-800 directory" (1-800 directory) [Trackback]
"omega psi phi fraternity songs" (omega psi phi fraternity songs) [Trackback]
"serpent Alchemy dragon lore" (serpent Alchemy dragon lore) [Trackback]
"sturgis web cam" (sturgis web cam) [Trackback]
"aggiungi sito" (aggiungi sito) [Trackback]
"personal injury lawyer virginia" (personal injury lawyer virginia) [Trackback]
"likable cameriera prostituta" (likable cameriera prostituta) [Trackback]
"hand crank dynamo" (hand crank dynamo) [Trackback]
"BODY FORTRESS GLUTAMINE" (BODY FORTRESS GLUTAMINE) [Trackback]
"naughty college girls gone wild" (naughty college girls gone wild) [Trackback]
"Keflex lasix" (Keflex lasix) [Trackback]
"alpine aire" (alpine aire) [Trackback]
"PLANE CRASH" (PLANE CRASH) [Trackback]
"lava lamps" (lava lamps) [Trackback]
"cascade locks" (cascade locks) [Trackback]
"DMAE Cream" (DMAE Cream) [Trackback]
"the talon tallahassee community college newspaper" (the talon tallahassee commu... [Trackback]
"Dumb Blonde Jokes" (Dumb Blonde Jokes) [Trackback]
"ugg australia in vancouver" (ugg australia in vancouver) [Trackback]
"quilt hanger" (quilt hanger) [Trackback]
"park rapids resort" (park rapids resort) [Trackback]
"mini digital video player" (mini digital video player) [Trackback]
"arc plasma temperature air" (arc plasma temperature air) [Trackback]
"Car Valuation Software Korea" (Car Valuation Software Korea) [Trackback]
"Swing Life away" (Swing Life away) [Trackback]
"internet payroll solutions" (internet payroll solutions) [Trackback]
Thursday, February 03, 2005 10:09:01 PM (Pacific Standard Time, UTC-08:00)
I finally had the occasion to do some ASP.net... It's not bad.

If you want it scripted, I would say to put this into a custom 404 error handler page. Then have that page redirect based on the query string. This is exactly what I'm doing at work, but my page looks up the redirection patterns in a mssql database (we have a lot of moved web pages).

The 301 status is a good thing - I hadn't thought of that.
Friday, February 04, 2005 6:00:45 AM (Pacific Standard Time, UTC-08:00)
I can't use an error handler because the pages are actually there. Both names resolve to the same IP. I just want search engines to replace the marklio.dnsalias.com hits with www.marklio.com hits so that in the future, when they ARE different IPs, there's no "loss" of my search engine juice on those hits.
marklio
Name
E-mail
(will show your gravatar icon)
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):