[wp-trac] [WordPress Trac] #33821: redirect_canonical does not consider port in $compare_original
WordPress Trac
noreply at wordpress.org
Thu Jun 12 00:27:37 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 needs- | Focuses:
test-info close |
-------------------------------------------------+-------------------------
Comment (by willshouse):
Thank you, everyone, for looking into this. It is indeed still an issue.
As mentioned in the original issue, the code in canonical.php, starting at
line 64 then, now line 70, does not consider a non-standard port in
building the redirect:
[[Image(https://i.postimg.cc/0rRPg6Cg/building-the-url.png)]]
The code is building a complete URL for a redirect but the port is never
considered.
My originally suggested patch should check for a port via the $_SERVER
environment variable for on Apache2:
[[Image(https://i.postimg.cc/ncpQQCJS/patch-notes.png)]]
**Logic**
- IF a server port is set
- AND if there is not already a port in the hostname
- AND if the port is a non-standard port
- THEN explicitly add it to the URL that we are building
I'm comparing the canonical.php file from 2015 with the latest one and I
don't see any changes to the section of code (starting at line 70) that is
building the URL, so I'm unsure of how it could have been resolved? Other
than perhaps a change in behavior where Apache would be adding the port
into the HTTP_HOST variable - but the suggested patch does check for this,
in order to avoid adding a port number twice.
Thanks again to everyone for considering the issue and working to make
WordPress better.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33821#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list