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:


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 new route
Route::get('{seoname}', array('as' => 'article', 'uses' => 'NewsController@getArticle'));

// The old route reinvented in Laravel routing
Route::get('news/{id}/{title}', function($id){
  $article = new Article($id);
  Redirect::route('article', $article->seoname, 301);

The result is that if you go to you automatically get redirected to in a blink of an eye.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.