This is a read-only archive!

Migrating away from Wordpress: permalinks

Work is progressing on my blog-rewrite in Clojure. It's been lots of fun and I keep adding features. Hopefully not too many features; the whole point of ditching Wordpress is that it's far too bloated. But my new blog already has categories and tags and pages with parent pages and so on and so forth. One of these days I'll actually start using it publicly, maybe.

One issue with migrating away from Wordpress is not to break all existing links that point to my Wordpress blog. Most people with Wordpress blogs (including myself) seem to use some date-based permalink structure, which I'd like to avoid.

I thought I'd have to set up some horrid mod_rewrite thing after the switch, to avoid breaking links, but actually Compojure's routes are powerful enough. Any request that looks like a Wordpress permalink, I pass to a redirect function which spits out some redirect headers to the new location. Simple enough, just a few lines of code of this sort:

(defn old-blog-redirect [name]
  (redirect-to (str "/blog/" name)))
(defservlet blog-servlet
  (GET "/2009/:m/:d/:name/" (old-blog-redirect (route :name))))

This redirects e.g. /2009/01/31/foo to /blog/foo.

Focusing so much on dates is kind of silly. A lot of blogs have a sidebar with a little calendar, or have a list of links to archives of all their posts by month. How useful is this really? Never once have I read someone's blog and thought "Wow, nice post. I wonder what this guy said in November of 2007. Good thing there's a link right there on the front page!"

Does anyone really care enough about the date something was posted, that the date needs to be encoded in the URL? The way I see it, the only thing people are going to use a date in a URL for is to say "That's too old, so I'm not reading that". How many people are going to be persuaded to read your blog by noticing (based on the URL) that a post is brand new, where otherwise they wouldn't have clicked the link? I have to think not many.

February 26, 2009 @ 5:03 PM PST
Cateogory: Programming

5 Comments

numerodix
Quoth numerodix on February 26, 2009 @ 10:19 PM PST

I think the date business is sort of a human readable hashing mechanism. You couldn't write entries likes "Today's links", which some people do, because the url, based on the entry title, would collide with others. Now you could just as well use postid or a hash there, but this way it actually tells you something potentially useful, which a postid doesn't.

I must say I continue to be skeptical of this undertaking of yours. I had similar thoughts for a while, but I ended up thinking "how long am I going to spend on replacing something that works well enough already?" Wordpress has its flaws, it's pretty awful to write plugins in php and a nicer language would no doubt make it easier and quicker to play around with it. But I decided I would rather spend my efforts on building something that doesn't exist than to replace something that does. You're taking on a big maintenance burden that I don't relish. Anyway, I hope it'll be a success!

Brian
Quoth Brian on February 27, 2009 @ 2:27 AM PST

I see your point about avoiding name collisions. I don't think I have any two post titles that collide but I can see some people might. If I was doing a daily links thing, I'd use /blog/todays-links-2009-02 probably.

Yeah Wordpress works pretty well, but there are just a few annoyances that have been bugging me forever. I'm using this as an excuse to learn Clojure better mostly.

So far I have 622 lines of Clojure, to replace almost everything I like out of Wordpress, and I'm almost done. That includes all of my HTML templates and the DB-to-struct layer (but it doesn't include the 1100 lines of code in Compojure itself). That's not too bad for maintenance.

In the wp-includes folder alone there are 29,247 lines of PHP. Not counting plugins or themes or HTML templates. I can't imagine what all of that is doing.

numerodix
Quoth numerodix on February 27, 2009 @ 2:54 AM PST

Well, if that's what you've accomplished then I suppose you've reached some sort of Paul Graham-y maximum join (or meet, perhaps) of the lattice. :D

Brian
Quoth Brian on February 27, 2009 @ 3:28 AM PST

Well, it's not hard to beat PHP when it comes to brevity. And I got rid of a lot of useless features.

But my version does some things that Wordpress doesn't. Zero database queries for most pages, thanks to Clojure refs. And the whole Markdown thing.

matt
Quoth matt on March 17, 2009 @ 4:52 AM PDT

/yyyy/post-title/ is my personal preference for urls. i was never big on the mm/dd stuff.