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

WordPress Trac noreply at wordpress.org
Mon Jun 16 19:41:47 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 needs-unit-tests changes-  |     Focuses:
  requested                                      |
-------------------------------------------------+-------------------------

Comment (by wojtekn):

 > PS: Remember you can test wordpress-develop by yourself and see what I'm
 seeing and tell me your experience. I know that you are maintaining
 WordPress Studio, but we might have to settle a middle ground here for
 tests.

 Yes, I'm testing with clean wordpress-develop.


 @SirLouen, now I see that my initial fix was addressing the host and port
 part, but there was still an issue with losing the schema. Still,
 everything worked well for me, thanks to the double redirect.

 With the issue in place:

 {{{
 % curl -I http://localhost:10013
 HTTP/1.1 301 Moved Permanently
 Server: nginx/1.26.1
 Date: Mon, 16 Jun 2025 19:27:15 GMT
 Content-Type: text/html; charset=UTF-8
 Connection: keep-alive
 X-Powered-By: PHP/8.2.27
 X-Redirect-By: WordPress
 Location: http://localhost/
 }}}

 With my initial patch:


 {{{
 % curl -I http://localhost:10013
 HTTP/1.1 301 Moved Permanently
 Server: nginx/1.26.1
 Date: Mon, 16 Jun 2025 19:29:43 GMT
 Content-Type: text/html; charset=UTF-8
 Connection: keep-alive
 X-Powered-By: PHP/8.2.27
 X-Redirect-By: WordPress
 Location: http://f261-79-117-215-65.ngrok-free.app/
 }}}

 The host and port are correct, but the `https` scheme set for the home URL
 is still not preserved.

 However, there was another redirect to the correct scheme at this time:


 {{{
 % curl -I http://f261-79-117-215-65.ngrok-free.app/
 HTTP/1.1 307 Temporary Redirect
 Content-Type: text/html; charset=utf-8
 Location: https://f261-79-117-215-65.ngrok-free.app/
 Date: Mon, 16 Jun 2025 19:31:11 GMT
 }}}

 It looks like the scheme is being lost when elements are being copied from
 home URL to redirect URL - the series of conditions copies host, path, and
 port from homeurl, but they miss the scheme:

 https://github.com/WordPress/wordpress-
 develop/blob/3410c205da5564cdb44bd9110c3b27f294583cf0/src/wp-
 includes/canonical.php#L601

 Those look like two different issues.

 I updated my patch to cover the scheme part, and now it works fine - it
 correctly redirects to homeurl and doesn't miss the scheme:

 {{{
 % curl -I http://localhost:10013
 HTTP/1.1 301 Moved Permanently
 Server: nginx/1.26.1
 Date: Mon, 16 Jun 2025 19:39:19 GMT
 Content-Type: text/html; charset=UTF-8
 Connection: keep-alive
 X-Powered-By: PHP/8.2.27
 X-Redirect-By: WordPress
 Location: https://f261-79-117-215-65.ngrok-free.app/
 }}}

 What do you think?

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


More information about the wp-trac mailing list