So Long Pretty URLs
Uniform Resource Locators
Ideally, URLs would live forever. Turns out, that's hard to manage. Sites die and take their URLs with them. Even more, sites change the software that runs them. That usually results in content moving to a new URL structure.
I've changed the software for this site several times over the past twenty years. Each change involved moving the URLs. I put in redirects to catch traffic to the old locations and send it to the new ones.
It works, but I've only do it for the most recent migration. I've done three or four since 2010 which means any links that point to URLs from that time period are now dead.
Aesthetics and Search Engine Optimization
For a few of the moves, changing the URLs helped get traffic to the site. Adding keywords and titles to the URLs worked as a way to get higher page ranks on search engines. As far as anyone can tell, that doesn't matter much these days. Even if it does, I no longer worry about it.
Beyond the search engine optimization, there's also an aesthetic quality to URLs. In an older version of my site, I spent a bunch of time setting things up to get URLs that were nothing by the domain name and the title of the page.
For example, the URL for this page would have been:
alanwsmith.com/so-long-pretty-urls
I still love the look of that. There's nothing there that doesn't need to be.
Everything's A Draft
I'd still be using those URLs except for one thing. They're based off the title of the post and I change those titles all the time.
My site is an extension of my grimoire. It has over nine thousand notes in it and I'm adding more all the time. Most start out as snippets that I ship to the site as very early drafts. The titles change as the pages mature.
Unlike changing software I have the option of leaving the URLs the same and simply letting them get out of sync with the title of the post. But, part of the reason I like the title based URLs is because the aesthetic ties to the title on the page.
So, we're back to redirects.
A Unique ID
One way to do redirects is to point all the old URLs to the new locations. That seems simple enough at first, but there's a complexity. What if you move a URL two times. Or, three. Or, ten.
You have to maintain a list of all the previous URLs and make sure they redirect properly. This can be done and automated, but you'd have to accommodate the full list across software changes as well.
Besides being fragile, doing that work is not where I want to spend my time.
I used another system for a while: a unique ID at the end of every URL. They end up looking like this:
alanwsmith.com/so-long-pretty-urls--2zqjnh3a
It's the same as before with the addition of a unique ID at the end. The power of this ID comes from the fact that it's the same for the page regardless of title changes. That let's me set them up so that if a request for a URL comes in that's no longer valid I can use it to redirect to the new one. So all of these:
alanwsmith.com/i-removed-pretty-urls--2zqjnh3a
alanwsmith.com/no-more-pretty-urls--2zqjnh3a
alanwsmith.com/goodbye-pretty-urls--2zqjnh3a
would all redirect to this automatically:
alanwsmith.com/so-long-pretty-urls--2zqjnh3a
Just An ID
The appended ID approach works, but it still takes work to implement.
So, I'm going the next step. I'm removing the title text all together. My URLs now look like this:
alanwsmith.com/en/2z/qj/nh/3a
With that change all the redirect work goes away. I can change page titles as much as I want and the URLs aren't affected.
The 20 Year Plan
My site is twenty years old. When I realized that, I started thinking about the next twenty years. A big part of that is thinking about what I want to spend my time working on. Redirects aren't it.
I'd rather spend time working on the content than jumping frameworks or setting up redirects. That lead me to create my own file format (neopolitan) and my own static site generator (neopoligin).
It also lead me to this decision.
I want my URLs to last, but I don't want to have to futz with them. And now, I don't have to.
-a
Endnotes
My site is built from a static site generator that outputs all the files when the site is built. The reason the IDs looks like this:
en/2z/qj/nh/3a
Instead of:
en2zqjnh3a
is because of the number of pages I have on the site.
Lots of software and apps start to bog down if you have more than a thousand or so things directly in a single directory. Since I've got a few thousand I split the ID into two character parts so each subdirectory doesn't have that much stuff in it.
At some point I'll add the titles back into the URLs. But, in a way that doesn't mess with the actual location. I'll do that by append the title after a ?. Like:
alanwsmith.com/en/2z/qj/nh/3a/?so-long-pretty-urls
That's not as pretty as:
alanwsmith.com/so-long-pretty-urls
but it at least keeps a human readable component in the URL. I like haven't that. As of press time: I just haven't gotten around to adding that back in.