WordPress.org

Make WordPress Core

Opened 2 years ago

#41712 new defect (bug)

canonical infinite redirect bug

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

Description

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:

<?php
// yes, again -- in case the filter aborted the request
        if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) {
                return;
        }

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

<?php
$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:

<?php
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 (0)

Note: See TracTickets for help on using tickets.