Make WordPress Core

Opened 3 years ago

Last modified 6 months ago

#41712 new defect (bug)

canonical infinite redirect bug

Reported by: yprince Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Canonical Keywords:
Focuses: Cc:


I had an infinite redirection problem caused by "redirect_canonical" (wp-includes\canonical.php)

I have a query string parameter ex: "http://mysite.com/mypage/?q=test%2C+test" and it was redirected infinitly to itself because of:

// yes, again -- in case the filter aborted the request
        if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) {

my $requested_url was in lowercase "http://mysite.com/mypage/?q=test%2c+test" because of:

$requested_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url);

but my $redirect_url was "http://mysite.com/mypage/?q=test%2C+test"

so the both url was different because of the "%2c" vs "%2C"

I solved it by adding:

add_filter( 'redirect_canonical', 'my_redirect_canonical', 10, 1 );
function my_redirect_canonical($redirect_url){
    $redirect_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $redirect_url);

    return $redirect_url;

Change History (1)

#1 @markparnell
6 months ago

  • Component changed from General to Canonical
Note: See TracTickets for help on using tickets.