[wp-trac] [WordPress Trac] #57260: Static home page redirect error using post name premalinks behind reverse proxy

WordPress Trac noreply at wordpress.org
Fri Dec 2 16:01:26 UTC 2022


#57260: Static home page redirect error using post name premalinks behind reverse
proxy
--------------------------+------------------------------
 Reporter:  kappe72       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Canonical     |     Version:  6.1.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Old description:

> In a WP site behind a reverse proxy all was working ok.
> I then set a static home page and all was still working.
> After I set post name permalinks, all pages kept working except home
> page, which had redirect errors.
> After some time spent researching the problem, I found that the problem
> was on line 69 of wp-includes/canonical.php: {{{#!php
> <?php
> $requested_url .= $_SERVER['HTTP_HOST'];
> }}}
> Instead of the value in $_SERVER['HTTP_HOST'], the value in
> $_SERVER['HTTP_X_FORWARDED_HOST'] should be used.
> I wonder if that could be definitively fixed changing line 69 of wp-
> includes/canonical.php with {{{#!php
> <?php
> $requested_url .= isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?
> $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
> }}}

New description:

 In a WP site behind a reverse proxy all was working ok.
 I then set a static home page and all was still working.
 After I set post name permalinks, all pages kept working except home page,
 which had redirect errors.
 After some time spent researching the problem, I found that the problem
 was on line 69 of wp-includes/canonical.php:
 {{{#!php
 <?php
 $requested_url .= $_SERVER['HTTP_HOST'];
 }}}
 Instead of the value in `$_SERVER['HTTP_HOST']`, the value in
 `$_SERVER['HTTP_X_FORWARDED_HOST']` should be used.
 I wonder if that could be definitively fixed changing line 69 of wp-
 includes/canonical.php with
 {{{#!php
 <?php
 $requested_url .= isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?
 $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
 }}}

--

Comment (by SergeyBiryukov):

 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57260#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list