Laravel, how to redirect as 301 and 302

后端 未结 6 1167
轮回少年
轮回少年 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条回答
  •  被撕碎了的回忆
    2021-02-02 07:19

    As of Laravel 5.8 you can specify Route::redirect:

    Route::redirect('/here', '/there');
    

    By default that will redirect with 302 HTTP status code, meaning temporary redirect. If the page is permanently moved you can specify 301 HTTP status code:

    Route::permanentRedirect('/here', '/there');
    /* OR */
    Route::redirect('/here', '/there', 301);
    

    Laravel docs: https://laravel.com/docs/5.8/routing#redirect-routes

提交回复
热议问题