Scott Hanselman

Maintaining PermaLinks when moving from .Text to DasBlog

January 25, '06 Comments [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
  -->
  <newtelligence.DasBlog.UrlMapper>
    <add matchExpression="(?&lt;basedir&gt;.*?)/archive/
                (?&lt;year&gt;\d{4})/(?&lt;month&gt;\d{2})/(?&lt;day&gt;\d{2})/
                (?&lt;postid&gt;\d+)\.aspx"
         mapTo="{basedir}/default.aspx?date={year}-{month}-{day}" />        
  </newtelligence.DasBlog.UrlMapper>

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
   -->
  <newtelligence.DasBlog.UrlMapper>
    <add matchExpression="(?&lt;basedir&gt;.*?)/archive/
                (?&lt;year&gt;\d{4})/(?&lt;month&gt;\d{2})/(?&lt;day&gt;\d{2})/
                (?&lt;postid&gt;\d+)\.aspx"
         mapTo="{basedir}/permalink.aspx?guid={postid}" />        
  </newtelligence.DasBlog.UrlMapper>

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Thursday, 26 January 2006 02:33:58 UTC
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:

http://www.hanselman.com/blog/DoesNotExist.aspx

Interestingly you have not set up a custom 404.html (tut, tut, tut, finger wagging etc):
http://www.hanselman.com/blog/DoesNotExist.html

I did and it works for non aspx pages + I am sure it worked with .Text:
http://www.dotnetworkaholic.com/DoesNotExist.html
http://www.dotnetworkaholic.com/DoesNotExist.aspx (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 :)
Thursday, 26 January 2006 06:58:35 UTC
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.
Scott Hanselman
Thursday, 26 January 2006 15:27:33 UTC
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.
Thursday, 26 January 2006 18:12:11 UTC
Interesting reason for using a real 404. Please post the one-line change, cheers!
Paul Lockwood
Thursday, 26 January 2006 18:20:29 UTC
Paul,

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.
Scott Hanselman
Friday, 27 January 2006 02:38:16 UTC
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.