Search code examples
wordpressfastcgi

wp-redirect(), php 5.5 and fastCGI


I recently had to move a heavily modified wordpress project to a bare bones server. Which I had to install everything from scratch. I tried both ubuntu 14.04 and centos 7. Ubuntu came with php 5.5 and centos with 5.4

My script used to work very well on hostgator. Which was a shared host and fastCGI was enabled there with php 5.4

However when I moved this to the new server any function that used wp-redirect() stopped working. But when I install fastCGI it suddenly starts to work. Never came across this before. DO you have any idea of why this is happening?


Solution

  • This is happening beacuse of the way WordPress is setting header statuses. See the implementation of wp_redirect here https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/pluggable.php#L1147

    See the extracted code here:

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

    You can examine the status_header function here status_header definition.

    A possible fix would be to amend the function or since PHP 5.4 you can use http_response_code.