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.