Laravel, how to redirect as 301 and 302

后端 未结 6 1166
轮回少年
轮回少年 2021-02-02 06:46

I cannot find info for redirecting as 301/302 in the Laravel docs.

In my routes.php file I use:

Route::get(\'foo\', function(){ 
    return Redirect::to(         


        
6条回答
  •  -上瘾入骨i
    2021-02-02 07:20

    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); 
    });
    

提交回复
热议问题