为什么 Zend Framework 的 $this->_redirect($url, array('code'=>301)) 会导致 302 代码?

发布于 2025-01-06 11:48:13 字数 135 浏览 3 评论 0原文

当我打电话时:

$this->_redirect($url, array('code'=>301));

我被重定向,但 http 代码是 302 而不是 301。知道为什么吗?

When I call:

$this->_redirect($url, array('code'=>301));

I get redirected, but the http code is 302 instead of 301. Any idea why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁的年少不轻狂 2025-01-13 11:48:13

_redirect($url, array $options = array()):重定向到另一个位置。此方法采用 URL 和一组可选选项。经过
默认情况下,它执行 HTTP 302 重定向。

尝试使用以下命令将重定向代码设置为 301:

$this->_helpers->redirector->setCode(301);

_redirect($url, array $options = array()): redirect to another location. This method takes a URL and an optional set of options. By
default, it performs an HTTP 302 redirect.

try setting redirect code to 301 using:

$this->_helpers->redirector->setCode(301);
把时间冻结 2025-01-13 11:48:13

看来使用 _redirect 方法总是会将代码设置为 302。如果您想手动更改响应代码,请使用 重定向器 代替。

It appears that using the _redirect method will always set the code to a 302. If you'd like to manually change the response code, use a redirector instead.

沉溺在你眼里的海 2025-01-13 11:48:13

在 Zend/Controller/Action/Helper/Redirector.php 中: _redirect 调用 $this->getCode(); getCode() 是 $this->_code 的简单 getter; _code 初始化为 302。

In Zend/Controller/Action/Helper/Redirector.php: _redirect called $this->getCode(); getCode() is simple getter for $this->_code; _code initialized with 302.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文