[wp-trac] [WordPress Trac] #59386: Paginated posts enter a redirect loop behind a CDN

WordPress Trac noreply at wordpress.org
Mon Nov 20 10:45:37 UTC 2023


#59386: Paginated posts enter a redirect loop behind a CDN
--------------------------+----------------------
 Reporter:  brentbaccala  |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Canonical     |     Version:
 Severity:  normal        |  Resolution:  invalid
 Keywords:                |     Focuses:
--------------------------+----------------------

Comment (by emmaevy):

 Your configuration with the entire site behind a CDN, using AWS
 CloudFront, is a supported setup. The issue seems related to the handling
 of paginated posts and trailing slashes. To address this, you can try
 adding the following code snippet to your theme's functions.php file:

 {{{

 ```php
 function remove_pagination_trailing_slash($redirect_url, $post,
 $leavename) {
     if (is_singular() && get_query_var('page')) {
         $page = get_query_var('page');

         if ($page > 1) {
             $redirect_url = untrailingslashit($redirect_url);
         }
     }

     return $redirect_url;
 }

 add_filter('post_link', 'remove_pagination_trailing_slash', 10, 3);
 }}}

 This code aims to remove the trailing slash for paginated posts,
 potentially resolving the redirect loop issue. Add this code to your
 theme's functions.php file and check if it helps.
 Use browser developer tools to inspect network requests and redirects or
 use this tool Link:[https://redirectchecker.com/ Redirect checker] This
 can help you identify trailing slash issue, http stats code and show you
 detail redirection path.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59386#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list