Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #57260


Ignore:
Timestamp:
12/02/2022 04:01:26 PM (2 years ago)
Author:
SergeyBiryukov
Comment:

Hi there, welcome to WordPress Trac! Thanks for the report.

This appears to be similar to #31288, #40013, #49970 and some other related tickets.

This is something that comes up often, but is not something that can be fixed due to the nature of handling client-provided headers, which is what's needed to address the issue. See comment:17:ticket:31288 for more info.

The long and short of it is that this is a server-level configuration issue with reverse proxy web servers. It's not a WordPress issue, and it's not limited to WordPress. There's no need to modify the redirect_canonical() function.

You just need to add something along the lines of the following code fragment to your wp-config.php file, before the /* That's all, stop editing! Happy publishing. */ comment, that way it won't be overwritten on updates:

if ( isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ) {
	$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}

Any proxy configuration is "supported" by WordPress, you just need to remap the $_SERVER['HTTP_HOST'] server variable based the particular proxy configuration you're using.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #57260 – Description

    initial v1  
    22I then set a static home page and all was still working.
    33After I set post name permalinks, all pages kept working except home page, which had redirect errors.
    4 After some time spent researching the problem, I found that the problem was on line 69 of wp-includes/canonical.php: {{{#!php
     4After some time spent researching the problem, I found that the problem was on line 69 of wp-includes/canonical.php:
     5{{{#!php
    56<?php
    67$requested_url .= $_SERVER['HTTP_HOST'];
    78}}}
    8 Instead of the value in $_SERVER['HTTP_HOST'], the value in $_SERVER['HTTP_X_FORWARDED_HOST'] should be used.
    9 I wonder if that could be definitively fixed changing line 69 of wp-includes/canonical.php with {{{#!php
     9Instead of the value in `$_SERVER['HTTP_HOST']`, the value in `$_SERVER['HTTP_X_FORWARDED_HOST']` should be used.
     10I wonder if that could be definitively fixed changing line 69 of wp-includes/canonical.php with
     11{{{#!php
    1012<?php
    1113$requested_url .= isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];