Posted: 05-11-2017

Laravel 5.5 dinamic Route redirect

Laravel 5.5 dinamic Route redirect

The Laravel 5.5 release was shipped with the new Route::redirect method.

Route::redirect('/news', '/blog', 301);

But what about to redirect route in a dinamic way

Route::redirect('/news/*', '/blog/*', 301);

You can do this whit this trick

Route::redirect('/news/'.collect(request()->segments())->last(),
'/blog/'.collect(request()->segments())->last());