Today I would like to pick a fight with WordPress. I’m still a huge fan of the company (Automattic). They’ve done a lot for us over the years and I have good friends who work there. But blog posts work better as beefs so forget all that.
Let’s talk about what a wrongy-wrongpants WordPress is with their aggressively over-clever canonical redirects feature! Say you write a post with URL “blog.bmndr.co/datasmithing” on your wordpress blog. If someone then tries to surf to “blog.bmndr.co/data” WordPress thinks to itself, “Aha, I know what this user meant to do! There’s only one URL on this blog that starts with ‘data’ so we can just silently redirect to it and the user will be so pleased!” Maybe whoever came up with that was misguidedly trying to adhere to the Principle of Least Astonishment or Do What I Mean.
And what’s so bad about that, you ask? If the user just forgot the final “g” in “datasmithing” is it somehow helping them to pedantically point out that they typoed the URL?
(Actually WordPress is even more egregiously magical. If you typo a URL in some other way, like transposing two characters, it just silently sends you to the front page of the blog.)
My answer is yes! Always be maximally pedantic! We have two other whole other blog posts about why that’s important in general — The Anti-Robustness Principle and The Anti-Magic Principle — but in this case there’s a very specific reason. Suppose we later actually write a new blog post with the URL “blog.bmndr.co/data”. WordPress will just silently break the old link that had been reliably pointing to the “datasmithing” one! [1] Facepalm!
Ok, my rant is over. Now let me show off the nifty thing the Beeminder blog does instead, now that we’ve moved off of WordPress. It might only be useful for me personally but since I know the URLs of our 13 years (!) of blog posts mostly by heart [2] and mostly type them from memory when linking to them, I’m pretty enamored with how narthur and I implemented the blog’s 404 pages. To show this off with an example, it’s hard to remember that the URL for our classic post on why we hate anti-charities is “/anticharity” but the Anti-Magic Principle post is “/magic”. So now check out what happens if you mix those up:
If you’re too lazy to click those, you’ll see something like this, for the example of trying to surf to “blog.beeminder.com/blog”:
I think this is within epsilon of the best of all worlds. At worst it’s an extra click for the case that you happened to type a strict prefix of an existing URL — no magic redirection. But since we’re now being nice and transparent about what happened — you’re getting a 404 error — we’re free to insert as much magic as we like into the list of suggestions, since the user can simply take or leave them. And we do! We throw in everything which has the mistyped URL as a strict prefix, as well anything that has it as a strict suffix. And if there aren’t any of those we get fancy and look for the URL with the closest Levenshtein distance. Here’s another screenshot, showing the hovertext helpfully explaining itself:
Is this overkill? Maybe! But clearly the blog is a labor of love and this makes me happy. So now the blog does Fancy 404s. You’re welcome.
PS: If you liked this, you’ll definitely like our post on Slytherin 404s.
Footnotes
[1] BTW, there actually is a Datasmithing post — we didn’t make that up! It’s a guest post from our friend Melissa Smith of Datasmithing. Melissa is a habit coach, which means she’ll help you tune up your habits, i.e., help you build and troubleshoot the habits and systems that you run your life on. Are you good at solving complex engineering problems, but bad at doing the dishes? She can help with that.
[2] Well, at least the 100ish “best of” posts that I find myself linking to the most.