As some of you may have noticed, I recently moved this blog from "lypang.com/devblog" to "kevinwilliampang.com". The motivation for this was purely cosmetic as I got tired of seeing "/devblog" in all my url paths.
Since the new site's structure is identical to the original site's structure, the migration only involved making the following change to the old site's global.asax file (if you're wondering why I broke up the url, it was to prevent the code syntax highlighter from interpretting the "//" in "http://" as the start of a comment
)
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string oldPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
string newPathAndQuery = oldPathAndQuery.ToLower().Replace("/devblog", "");
string url = "http:/" + "/www.kevinwilliampang.com" + newPathAndQuery;
Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", url);
Response.End();
}
What this code does is trigger a 301 permanent redirect on any request for a page on the old lypang.com/devblog site. It persists the requested path and query so that the redirection is seemless to the end user (e.g. a link to http://lypang.com/devblog/post/metrosexual-developers.aspx will 301 redirect to http://www.kevinwilliampang.com/post/metrosexual-developers.aspx).
Obviously, for more complex sites and/or migrations this sledgehammer of a solution would not be sufficient. In those instances, you would most likely be better off by redirecting to a static page and losing the path/query persistence or putting custom redirect logic on each individual page to ensure that they redirect properly. But for anyone who simply wants to move their website to another domain, this is a quick and easy way to do it.



Plus, everyone subscribed to your RSS feed gets all the recent posts showing up as new again, so that’s a big plus if you were trying to remind them of your website.
Yeah, I noticed that too. Oops.