[wp-trac] [WordPress Trac] #33821: redirect_canonical does not consider port in $compare_original

WordPress Trac noreply at wordpress.org
Wed Jun 18 14:56:26 UTC 2025


#33821: redirect_canonical does not consider port in $compare_original
-------------------------------------------------+-------------------------
 Reporter:  willshouse                           |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Canonical                            |     Version:  2.3
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-test-info has-unit-    |     Focuses:
  tests needs-testing                            |
-------------------------------------------------+-------------------------

Comment (by wojtekn):

 Thanks @SirLouen !

 Separately from the above efforts, I tried to look into the exact issue
 reported by @willshouse. The description points to the case in which
 `$requested_url` is not provided to `redirect_canonical()`, and then this
 function assembles it based on the `$_SERVER` array values.

 I'm happy to look into this one, too. As there were comments pointing out
 that it might be related to incorrect server configuration, I would
 appreciate sharing the test that targets `redirect_canonical()` and allows
 to reproduce the issue. I tried this one, but couldn't cause it to fail:

 {{{
         public function test_domain_and_port_redirections_ssl() {
                 update_option( 'home', 'https://example.com:8443' );
                 update_option( 'siteurl', 'https://example.com:8443' );

                 // Simulate a request to a non-canonical domain.
                 $_SERVER['HTTP_HOST']   = 'example.com';
                 $_SERVER['REQUEST_URI'] = '/';

                 $redirect = redirect_canonical( null, false );

                 $this->assertSame( 'https://example.com:8443/', $redirect,
 'Could not redirect' );
         }
 }}}

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


More information about the wp-trac mailing list