[wp-trac] [WordPress Trac] #33821: redirect_canonical does not consider port in $compare_original
WordPress Trac
noreply at wordpress.org
Fri Jun 13 12:41:06 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 needs-refresh |
-------------------------------------------------+-------------------------
Changes (by SirLouen):
* keywords: has-patch needs-unit-tests needs-test-info close => has-patch
needs-unit-tests changes-requested needs-refresh
Comment:
== Test Report
=== Description
This report can't validate that the indicated patch works as expected.
Patch tested:
https://core.trac.wordpress.org/attachment/ticket/33821/add_canonical_port_check.patch
=== Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 137.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Three 1.6
- MU Plugins: None activated
- Plugins:
* Test Reports 1.2.0
=== Testing Info
- I've followed
[https://core.trac.wordpress.org/ticket/33821?replyto=26#comment:26 these
instructions].
- Instead of Local, I'm using the `wordpress-develop` build (Port 8889)
- I can reproduce the issue
=== Expected results
- The port is respected
=== Actual Results
1. ❌ Issue not resolved with patch.
=== Additional Notes
Replying to [comment:26 wojtekn]:
> Expected behavior: User is redirected to `https://MY-NGROK-URL.ngrok-
free.app`
> Current behavior: User is redirected to `http://localhost`
I've been able to reproduce this, using the `wordpress-develop` build
{{{
HTTP/1.1 301 Moved Permanently
Server: nginx/1.27.5
Date: Fri, 13 Jun 2025 12:04:24 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/8.2.28
X-Redirect-By: WordPress
Location: http://localhost/
}}}
But I've applied
[https://core.trac.wordpress.org/attachment/ticket/33821/add_canonical_port_check.patch
the patch], and nothing seems to be changing here.
During debug I've noted that $_SERVER['SERVER_PORT'] is 80 at the point,
while requested $_SERVER['HTTP_HOST'] is http://localhost:8889
At some point, the port is stripped but not where the patch expects. Here
{{{
if ( strpos( $_SERVER['HTTP_HOST'], ':' ) == false ) {
}}}
The condition is not applying, because as I say the HTTP_HOST has already
the port as expected.
I think the problem could be around L616
{{{
$user_home = parse_url( home_url() );
if ( ! empty( $user_home['host'] ) ) {
$redirect['host'] = $user_home['host'];
}
if ( empty( $user_home['path'] ) ) {
$user_home['path'] = '/';
}
// Handle ports.
if ( ! empty( $user_home['port'] ) ) {
$redirect['port'] = $user_home['port'];
} else {
unset( $redirect['port'] );
}
}}}
Here it doesnt matter which port is coming as long as the home url doesnt
have port, it will be stripped.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33821#comment:27>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list