Self-Healing URLs
isabel
December 10, 2023
I have been working on the creation of this version of my website for a while and when I finally thought I was done, I was introduced to the concept of self-healing URLs.
Self-healing URLs are designed in a way that if a user was to type in a URL as
long as a certain part of the URL is correct, the user will be redirected to the
correct page. This is useful for when a user is trying to access a page that has
been moved or deleted.
For example, if a user was to type in /blog/gaoengioa-2 they would be redirected to /blog/self-healing-urls-2 as the only important part of the URL is the "2" in this case, which refers to the second blog post by ID.
To implement this I had to make a few changes to my code. The original way that
the post data was being fetched was by using the slug of the post. This meant
that if the slug was incorrect, the post would not be found and the user would
be redirected to a 404 page. To fix this I had to change the way that the post
was being fetched to use the ID of the post instead. This meant that if the slug
was incorrect, the post would still be found and the user would be redirected to
the correct page.
Then all that was left was to ensure all links were using the new slug format.
This was done by changing the way that the slug was being created. Instead of
using the title of the post, the slug was created using the title and the ID of
the post. This meant that the slug would always be unique and would always be
the same for the same post.
Inspiration
The original idea for this post comes from: https://www.youtube.com/watch?v=a6lnfyES-LA
Discussion in the ATmosphere