Laravel,如何重定向为301和302 [英] Laravel, how to redirect as 301 and 302

查看:218
本文介绍了Laravel,如何重定向为301和302的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Laravel文档中找不到以301/302重定向的信息.

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

在我的routes.php文件中,使用:

In my routes.php file I use:

Route::get('foo', function(){ 
    return Redirect::to('/bar'); 
});

默认情况下是301还是302?有没有办法手动设置?知道为什么会在文档中将其省略吗?

Is this a 301 or 302 by default? Is there a way to set it manually? Any idea why this would be omitted from the docs?

推荐答案

无论何时不确定,都可以使用源代码查看Laravel的API文档. 重定向器类$status = 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.

您可以使用to()方法定义状态代码:

You can define the status code with the to() method:

Route::get('foo', function(){ 
    return Redirect::to('/bar', 301); 
});

这篇关于Laravel,如何重定向为301和302的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆