Make WordPress Core

Opened 3 years ago

#40013 new defect (bug)

Inifinite loop in subfolder

Reported by: dSero Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.2
Component: General Keywords:
Focuses: Cc:



We implemented WP on a dedicated server, where /blog serves as a subfolder behind an AWS application ELB that directs all /blog traffic to this server. The ELB also offloads the SSL.

When configuring the WP, we faced an inifinte loop (301 redirect) on the /blog/ path, while intenral paths works great (/blog/trial for exmample).

When debugging the code, we found out that the "protect against chained redirects" in /var/www/html/wp-includes/canonical.php actually doesn't work, as the if state should be true instead of false:

Please find trace below:

Pages flow:
require_once( ABSPATH . WPINC . '/template-loader.php' );
do_action( 'template_redirect' ); ==>
add_action( 'template_redirect', 'redirect_canonical' );
The actual broken code is in:
=> $redirect_url is empty inside, so return;
And the broken code in it is:

!redirect_canonical($redirect_url, false) 
                // protect against chained redirects
                if (!redirect_canonical($redirect_url, false) ) {
                        wp_redirect($redirect_url, 301);

Looks like there is a bug when there a sub folder model is being used.
Instead of protecting from chained redirects, the if actually causes them, since the return from the funciton when URLs are the same if return;
So correct code should be:

if (redirect_canonical($redirect_url, false) ) {

And not

if (!redirect_canonical($redirect_url, false) ) {

Change History (0)

Note: See TracTickets for help on using tickets.