I have recently set up a second blog on my WordPress multisite. The primary blog on the Multisite is www.example.com
, and the second blog I have set up two days ago is www.example2.org
.
Unfortunately, when going to www.example2.org
, WordPress redirects to https://www.example.com/wp-signup.php?new=
On the same server, I have set up a corresponding test Multisite, with test.example.com
being the primary blog and test.example2.org
the second blog. It is working without a problem.
The Multisite-related .htaccess
and wp-config.php
settings are the same for both the test and the live Multisite, so that wouldn’t be the problem. I’ve also verified that on the live Multisite I have www.example2.org
correctly set in the wp_blogs
table, and also it is correctly set as https://www.example2.org
on the siteurl
and home
rows of the wp_2_options
table (the _2_
part corresponding to the blog ID on the Multisite).
I would appreciate any suggestions on why this redirect is happening and/or how to resolve it. I don’t even know which file is issuing the redirect (I don’t think it’s wp-signup.php
) so I can’t look at the relevant code to debug it further.
After many hours of debugging and despair, the problem is now solved. It turned out to be a very obscure thing.
The redirect is issued by the function ms_load_current_site_and_network()
inside /wp-includes/ms-load.php
. It was issuing the redirect because /wp-includes/ms-settings.php
was not able to set a domain. The reason it was not able to set a domain is because $_SERVER['HTTP_HOST']
was not set.
$_SERVER['HTTP_HOST']
not being set had to do with the PHP setting auto_globals_jit. It was set to On, resulting in the $_SERVER
array not being set (as explained in this comment). Even though $_SERVER['HTTP_HOST']
and the rest were defined when loading a single php file with phpinfo();
in it, they were not defined when loading WordPress’s php files. And that led to the redirect.
Setting auto_globals_jit
to Off in php.ini resolved it.
Bonus info:
The issue was additionally made more complicated by some form of caching (which I couldn’t pin down or clear). So I had to rely on behavior that I saw occur only once and couldn’t replicate afterwards. For example, I created a separate php file to just check if $_SERVER['HTTP_HOST']
is set – and initially it wasn’t. Following the suggestion from the comment, I used $_SERVER['HTTP_HOST']
twice in the php file – and immediately saw that it was now set. However, when reverting the change and having $_SERVER['HTTP_HOST']
only once in the php file, it still remained set – suggesting I was seeing a cached response. I coulnd’t get it to break again after I fixed it once.
Just documenting this here in case someone encounters similar behavior.