Make WordPress Core

Opened 11 months ago

Last modified 9 months ago

#58803 new defect (bug)

Infinite loop in canonical.php

Reported by: emerlen's profile emerlen Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 6.2
Component: Canonical Keywords:
Focuses: Cc:


A site 24x7 monitor that points to a URL on our website leads to an error with infinite loops reported.

This error started after the page being pointed by the monitor received a new Slug, leading to HTTP redirection due to autocomplete to the closest URL. Still, I believe it occurs only during periods of transient availability of our shared host.

Looking at the source code [REF2] I believe there is potential for an infinite loop on line 800. Possible fix in [REF3].

By assigning the result of redirect_canonical() to a variable ($chained_redirect) before the if statement, we ensure that the same value is used throughout the if block preventing unnecessary recursive calls.



HTTP/1.1 508 Loop Detected
Server : nginx



Protect against chained redirects.

$chained_redirect = redirect_canonical($redirect_url, false);
if (!$chained_redirect)

Change History (1)

#1 @emmaevy
9 months ago

$chained_redirect = redirect_canonical($redirect_url, false);
if (!$chained_redirect)

It help prevent the infinite loop by ensuring that the same result of redirect_canonical() is consistently used within the if block. This approach might mitigate the recursive redirection issue and the resulting infinite loop.
Steps: You can manually check on browser developer tools to inspect network requests and redirects or use this tool Link:redirect checker This can help you with Canonical URLs and identify the loop and detail redirection chain and its http status code.

Last edited 9 months ago by emmaevy (previous) (diff)
Note: See TracTickets for help on using tickets.