[wp-trac] [WordPress Trac] #33821: redirect_canonical does not consider port in $compare_original
WordPress Trac
noreply at wordpress.org
Fri Feb 14 09:03:50 UTC 2025
#33821: redirect_canonical does not consider port in $compare_original
-------------------------------------------------+-------------------------
Reporter: willshouse | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
| Release
Component: Canonical | Version: 2.3
Severity: normal | Resolution:
Keywords: has-patch needs-unit-tests needs- | Focuses:
testing |
-------------------------------------------------+-------------------------
Comment (by wojtekn):
I spotted a similar issue today. Doesn't the following code cause it?
{{{
/*
* Ignore differences in host capitalization, as this can lead to
infinite redirects.
* Only redirect no-www <=> yes-www.
*/
if ( $original_host_low === $redirect_host_low
|| ( 'www.' . $original_host_low !== $redirect_host_low
&& 'www.' . $redirect_host_low !==
$original_host_low )
) {
$redirect['host'] = $original['host'];
}
}}}
Let's assume the hosts look as follows:
Requested: http://localhost:8888
Canonical: http://some.custom.domain.dev
The variables look as follows:
{{{
$original_host_low = 'localhost';
$redirect_host_low = 'some.custom.domain.dev';
}}}
How conditions resolve:
- 'localhost' === 'some.custom.domain.dev' -> false
- 'www.' . 'localhost' !== 'some.custom.domain.dev' -> true
- 'www.' . 'some.custom.domain.dev' !== 'localhost' -> true
As the second and third parts resolve to true, the whole condition
resolves, and the redirect host is replaced with the original host.
Then, later in the flow, the user is redirected to http://localhost
(without port) instead of http://some.custom.domain.dev.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33821#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list