Laravel – Many routes lead to Rome, but most got prettier!

But we’ve moved on from dirt roads to cobblestone to asphalt. Let’s modernize our Laravel routes and make the old ones deprecated, not broken!

I had a few route that needed a little modification, but I knew people bookmarked it and Google is indexing daily so I wanted to keep it yet deprecate it with a decent HTTP 301 Moved Permanently redirect status.

My old website had URL’s like the following:

    o

  • mysite.com/news/46/a%20generic%20article%20about%20html
  • o

  • mysite.com/news/104/url%20encoding%20explained

It was an easy, but ugly solution against duplicate titles plus horrible URL encoding result, so I figured out a way to make the titles more descriptive and unique and since the new site was made with Laravel I came up with the following:

The result is that if you go to mysite.com/news/46/a%20generic%20article%20about%20html you automatically get redirected to mysite.com/a-beginners-introduction-to-html in a blink of an eye.

Leave a Reply

Your email address will not be published. Required fields are marked *