Laravel, how to redirect as 301 and 302
Whenever you are unsure, you can have a look at Laravel's API documentation with the source code. The Redirector class defines a $status = 302
as default value.
You can define the status code with the to()
method:
Route::get('foo', function(){
return Redirect::to('/bar', 301);
});
I update the answer for Laravel 5! Now you can find on docs redirect helper:
return redirect('/home');
return redirect()->route('route.name');
As usual.. whenever you are unsure, you can have a look at Laravel's API documentation with the source code. The Redirector class defines a $status = 302 as default value (302 is a temporary redirect).
If you wish have a permanent URL redirection (HTTP response status code 301 Moved Permanently), you can define the status code with the redirect() function:
Route::get('foo', function(){
return redirect('/bar', 301);
});