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

WordPress Trac noreply at wordpress.org
Tue Sep 19 01:47:05 UTC 2023


#59386: Paginated posts enter a redirect loop behind a CDN
--------------------------+-----------------------------
 Reporter:  brentbaccala  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Canonical     |    Version:  6.3.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I've got a server (u20.freesoft.org) that sits behind Amazon's CDN, which
 is caching for the DNS name www.freesoft.org.  "www.freesoft.org" is set
 for the WordPress Address and the Site Address in General Settings, and
 everything is mostly working fine.  I'm using the twenty seventeen theme
 (version 3.2) and the "Post name" permalink structure, wordpress version
 6.3.1.

 The problem arises for paginated posts, and is related to trailing
 slashes.  If I request a URL like https://www.freesoft.org/blogs/soapbox
 /my-confession/, it works fine for the first page (this is a paginated
 post).  The CDN requests the page from u20.freesoft.org, and the links
 returned in the HTML look like this:

 {{{
 <a href="https://www.freesoft.org/blogs/soapbox/my-confession/2/" class
 ="post-page-numbers">
 }}}

 The problem arises when a browser tries to access that link.  The CDN
 sends it to https://u20.freesoft.org/blogs/soapbox/my-confession/2/, and
 this happens:

 {{{
 ubuntu at u20:~$ wget -O- https://u20.freesoft.org/blogs/soapbox/my-
 confession/2/ 2>&1 | head
 --2023-09-18 18:38:40--  https://u20.freesoft.org/blogs/soapbox/my-
 confession/2/
 Resolving u20.freesoft.org (u20.freesoft.org)... 172.30.2.192
 Connecting to u20.freesoft.org (u20.freesoft.org)|172.30.2.192|:443...
 connected.
 HTTP request sent, awaiting response... 301 Moved Permanently
 Location: https://www.freesoft.org/blogs/soapbox/my-confession/2/
 [following]
 --2023-09-18 18:38:40--  https://www.freesoft.org/blogs/soapbox/my-
 confession/2/
 Resolving www.freesoft.org (www.freesoft.org)... 172.30.2.192
 Connecting to www.freesoft.org (www.freesoft.org)|172.30.2.192|:443...
 connected.
 HTTP request sent, awaiting response... 200 OK
 }}}

 Which, you see, is a redirect loop.  I can take the trailing slash off the
 URL and it works, but that isn't how the links are formatted on the first
 page.

 I've been looking through the code base, and I've honed in on this block
 of code in wp-includes/canonical.php:

 {{{
                 // Post paging.
                 if ( is_singular() && get_query_var( 'page' ) ) {
                         $page = get_query_var( 'page' );

                         if ( ! $redirect_url ) {
                                 $redirect_url = get_permalink(
 get_queried_object_id() );
                                 $redirect_obj = get_post(
 get_queried_object_id() );
                         }

                         if ( $page > 1 ) {
                                 $redirect_url = trailingslashit(
 $redirect_url );

                                 if ( is_front_page() ) {
                                         $redirect_url .=
 user_trailingslashit( "$wp_rewrite->pagination_base/$page", 'paged' );
                                 } else {
                                         $redirect_url .=
 user_trailingslashit( $page, 'single_paged' );
                                 }
                         }

                         $redirect['query'] = remove_query_arg( 'page',
 $redirect['query'] );
                 }
 }}}

 I'm wondering if there should be some test here to check if $redirect_url
 is false and leave it alone.  It looks to me like it always sets
 $redirect_url for a paginated post, and I'm not sure if that's right.

 But I really don't know the code base at all.  It's just a guess.  Maybe
 it's a useful guess, or maybe I don't have a clue.

 Anyway, it's a problem for my site, and probably for others.  Hopefully
 somebody can help get it resolved.

 Thanks!

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


More information about the wp-trac mailing list