Table of contents

laravel redirect

In this post, you will learn some Laravel Redirect Cheat Sheet that is useful in your Laravel development.

 

It will redirect to another page with status 302 indicating a temporary redirect.

//redirect to another page. Status is 302 indicating temporay redirect
Route::redirect('/page', '/new-page');

 

This example can define page status as 3rd parameter which indicates a permanent redirect.

//can pass status as 3rd Parameter. 301 indicates permanent redirect
Route::redirect('/page', '/new-page', 301);

 

Same as above example but no need to set a 301-page status

//Same as above
Route::permanentRedirect('/page', '/new-page');

 

This example shows that we can redirect with parameters.

//Redirect along with the parameter
Route::redirect('/page/{param}', '/new-page/{param}');

 

This example can redirect with all parameters available.

//Redirect with all parameters
Route::redirect('/page/{params?}', '/new-page/{params?}')->where('params', '(.*)');