wp-redirect(), php 5.5 和 fastCGI

wp-redirect(), php 5.5 and fastCGI

我最近不得不将一个经过大量修改的 wordpress 项目移动到一个简单的骨架服务器上。我必须从头开始安装所有东西。我尝试了 ubuntu 14.04 和 centos 7。Ubuntu 附带 php 5.5,centos 附带 5.4

我的脚本过去在 hostgator 上运行得很好。这是一个共享主机,并且在那里启用了 fastCGI php 5.4

然而,当我将其移至新服务器时,任何使用 wp-redirect() 的函数都停止工作。但是当我安装 fastCGI 时它突然开始工作了。以前从未遇到过这个。你知道为什么会这样吗?

这是因为 WordPress 设置 header 状态的方式。在此处查看 wp_redirect 的实现 https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/pluggable.php#L1147

在此处查看提取的代码:

if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' )
  status_header($status); // This causes problems on IIS and some FastCGI setups

您可以在此处检查 status_header 函数 status_header definition

可能的解决方法是修改函数,或者自 PHP 5.4 起您可以使用 http_response_code.