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

WordPress Trac noreply at wordpress.org
Tue Jun 17 09:52:40 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 2nd-opinion                          |
-------------------------------------------------+-------------------------

Comment (by wojtekn):

 > So this is my main question: What is the concern of leaving the Location
 localhost if the site works well.

 The site doesn't work well in this case - the redirect from the requested
 URL to the canonical is broken.

 As a user, I want to do the following:

 1. Start Local (or Studio after removing our fix for that bug from the
 codebase)
 2. Ensure to have 'Router mode' set to localhost (Preferences -> Advanced)
 3. Create a new site and start it
 4. Note site's host, e.g. localhost:10018
 5. Click 'Open site' in the app UI
 6. Confirm that http://localhost:10018/ opens correctly and serves the WP
 site


 Now, I want to use this site with Ngrok and have the 'Open site' link in
 the app still working:

 1. Start the ngrok tunnel pointing to the site:
 {{{
 ngrok http 10018
 }}}
 2. Update wp-config.php and set canonical URLs:
 {{{
 define( 'WP_HOME', 'https://MY-NGROK-URL.ngrok-free.app');
 define( 'WP_SITEURL', 'https://MY-NGROK-URL.ngrok-free.app');
 }}}
 3. Click 'Open site' in the app UI
 4. http://localhost:10018/ now incorrectly redirects to http://localhost
 instead of Ngrok URL, which is configured in `wp-config.php` as a
 canonical URL


 I can access the site using the Ngrok URL directly, but to have great UX I
 would like to be able to use the 'Open site' link in local environment
 app. The local environment app serves the site under localhost:port, but
 as I configured the canonical URL in the config file, I expected WordPress
 will redirect such a request correctly.

 Trying to define the issue in the shortest words:

 > "WordPress incorrectly redirects requested URL with port to the
 canonical URL"

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


More information about the wp-trac mailing list