Written by Benjamin Crozat on .
How to make your URLs unbreakable in a Laravel project
I just can’t remember where I learned this technique. But anyway, I’ll share it.
On this blog, the ID and the slug are part of posts URLs. It looks like
Whoever write blog posts and impatiently publish them knows that at some point, you’ll probably have to tweak the title, which is problematic if you already shared your post on social media, since the URL will be broken. Some people use this kind of solution. While it works perfectly, I don’t like it. it could be way simpler than that.
Let’s say I changed the title of my blog post from “Foo” to “Bar”. If someone access the old URL (
https://hello-world.test/blog/1/foo), we should redirect to (
https://hello-world.test/blog/1/bar). Here’s how I do it on this blog:
Until next time!