Scott Hanselman

Maintaining PermaLinks when moving from .Text to DasBlog

January 25, 2006 Comment on this post [6] Posted in DasBlog
Sponsored By

I believe very strongly in the concept of the PermaLink. They aren't TempLinks, they are meant to be as permanent as possible. When people want their hair done, they get perms, not temps.

When I moved this blog from Radio Userland back in September of 2003, I was worried that my 17 readers at the time wouldn't find the new blog. So, using Clemens' schema, I maintained my permalinks (mostly) via a funky redirect mechanism. If you should still find some old Radio urls and schmutz from my old blog, you'll be redirected to the old content that was imported here.

I've seen a number of folks migrate their content from .Text to DasBlog and there's a half-dozen utilities to do it, it's not too hard. What is more difficult/tricky is maintaining your old permalinks. Joshua Flanagan has contributed some stuff to the DasBlog project recently (that we'll make public later) but he also made some changes to the default web.config that can help folks maintain their URLs.

DasBlog has a very flexible RegularExpression-based URL Mapper (again, there's lots out there, not just DasBlog's) that will allow you to add matches, take them apart, and reassemble the results. Here's two for mapping .Text URLs to DasBlog. The end result is that requests for your old (non-existent) .Text pages are redirected to DasBlog.

This one should be used if you didn't use the old .Text PostID as the permalink GUID in DasBlog, so it's date-based. This is what Joshua added. Note that you'll likely already have the "<newtelligence.DasBlog.UrlMapper>" section, so just add the <add> element. Note also that I've split the regex up for formatting purposes, but the matchExpression should have NO whitespace.

  <!-- Translates
    FROM: /blog/archive/2004/07/27/194.aspx
    TO: /blog/default.aspx?date=2004-07-27
    <add matchExpression="(?&lt;basedir&gt;.*?)/archive/
         mapTo="{basedir}/default.aspx?date={year}-{month}-{day}" />        

This one should be used if you DID use the old .Text PostID as the permalink GUID in DasBlog, which is my preferred mechanism. The GUIDs in DasBlog just need to be unique, and in this case we can toss the date info in the URL. 

   <!-- Translates
     FROM: /blog/archive/2004/07/27/194.aspx
     TO: /blog/permalink.aspx?guid=194
    <add matchExpression="(?&lt;basedir&gt;.*?)/archive/
         mapTo="{basedir}/permalink.aspx?guid={postid}" />        

You can shape you URLs anyway you like. Maybe you brought your Radio content over like Jeff Sandquist, or if you've migrated content from other (homegrown) blogs to DasBlog.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
January 26, 2006 6:33
Guilty as charged. Spookily Michael convinced me to me to DasBlog too.

One thing that has bugged me for a while (but not enough to start digging into source code) is that (presumably) the url re-writer mechanism does not re-direct me to the home page when a url does not exist. Try this:

Interestingly you have not set up a custom 404.html (tut, tut, tut, finger wagging etc):

I did and it works for non aspx pages + I am sure it worked with .Text: (does not forward to home page)

Am I missing something, or is this an issue inside DasBlog? Yes I know I should get it from CVS and start digging… when this home DIY, .Net community work, 6 minute mile etc are all done I’ll get there :)
January 26, 2006 10:58
I personally don't like custom 404s...a 404 pretty much says it all ;) tain't there! Plus, I don't like wasting bandwidth when spammers go hunting, so there are other instances where I screw'em with a 404.

That's a one line change if it bothers you. Let me know.
January 26, 2006 19:27
Aha - now I see what you mean by just using the GUID format. I just made life harder for myself by not preserving the postID when moving to dasBlog.
January 26, 2006 22:12
Interesting reason for using a real 404. Please post the one-line change, cheers!
January 26, 2006 22:20

In PermaLink.aspx.cs, look at the first 6 lines of LoadEntries(). If an entry wasn't found by this point, we 404 them. Change that section before the "return null" to a Response.Redirect and you should be in business.
January 27, 2006 6:38
Ahsante Sana Scott! I'll give a try asap.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.