Make WordPress Core

Opened 8 years ago

Closed 6 years ago

Last modified 6 years ago

#45337 closed defect (bug) (fixed)

Strange pagination issue

Reported by: sachit.tandukar Owned by: SergeyBiryukov
Priority: normal Milestone: 5.5
Component: Rewrite Rules Version: 4.4
Severity: normal Keywords: needs-patch needs-unit-tests
Cc: Focuses:

Description

Hi,

I am facing strange pagination issue in WordPress. I could replicate it on other major WordPress websites as well apart from the one I am working on.

If you check this website: ​https://highlandexpeditions.com/blog/, everything works fine. Pagination works fine too.

However, if you visit ​https://highlandexpeditions.com/blog/2/, you will get the same page as ​https://highlandexpeditions.com/blog/. But the pagination links are ruined. You will have pagination links like (​https://highlandexpeditions.com/blog/2/page/2/, ​https://highlandexpeditions.com/blog/2/page/3/) which goes to 404 page.

I think WordPress should show 404 for ​https://highlandexpeditions.com/blog/2/ rather than showing ​https://highlandexpeditions.com/blog/.

I don't think it has anything to do with themes or plugin. Because another popular website like ​https://www.wpbeginner.com/blog/ has the same issue. If you visit this URL (​https://www.wpbeginner.com/blog/2/), you will find its pagination URL is wrong. I am able to replicate it on other websites as well.

Thanks.

Attachments (1)

45337.diff​ (588 bytes ) - added by jeremyfelt 7 years ago.

Download all attachments as: .zip

Change History (11)

@jeremyfelt
7 years ago

#1 follow-up: @jeremyfelt
7 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone Awaiting Review → Future Release
  • Severity major → normal
  • Version 4.9.8 → 4.4

Hi @sachittandukar, thanks for opening a ticket.

This seems similar to #28081, but likely different enough to have its own ticket. That deals with the paged query variable and this deals with page. This was partially fixed in #11694, which introduced the current page checking in [34492].

There are (at least) two ways in which this presents itself:

First: when a request is made to any is_singular() post/page with /2/ appended to the URL, WordPress checks for an instance of <!--nextpage--> in the content. If it exists, and it matches the page number, $success is set to true and the page is loaded. If the next page marker does not exist, there is no current check that flags the content for 404 if a page number is part of the URL. For that, we could do something like 45337.diff​ to return a 404 if content is not paged.

Second: (highlighted in the ticket description), when a page is set as the page_for_posts, is_singular() is false and the logic handling <!--nextpage--> is skipped entirely. Earlier in the process, the query object was populated with posts, so as far as handle_404() is concerned, is_home() is true and the page can be loaded as is. The fix for this seems a little more complicated and _could_ be handled earlier in the process.

#2 @SergeyBiryukov
7 years ago

#48972 was marked as a duplicate.

#3 @SergeyBiryukov
7 years ago

#44587 was marked as a duplicate.

#4 @SergeyBiryukov
6 years ago

In 47727:

Canonical: Redirect paged requests for non-paginated posts to the post permalink.

This avoids displaying duplicate content of the same post under different URLs and ensures the canonical URL is correct.

Previously, requests for invalid page numbers were only redirected to the post permalink if the post was actually paginated using the <!--nextpage--> marker.

Follow-up to [34492].

Props jeremyfelt, prografika, sachit.tandukar, subrataemfluence, hronak, ekatherine, henry.wright, chesio, dd32, SergeyBiryukov.
Fixes #40773. See #45337, #28081, #11694.

#5 in reply to: ↑ 1 @SergeyBiryukov
6 years ago

Replying to jeremyfelt:

There are (at least) two ways in which this presents itself:

First: when a request is made to any is_singular() post/page with /2/ appended to the URL, WordPress checks for an instance of <!--nextpage--> in the content. If it exists, and it matches the page number, $success is set to true and the page is loaded. If the next page marker does not exist, there is no current check that flags the content for 404 if a page number is part of the URL. For that, we could do something like 45337.diff​ to return a 404 if content is not paged.

Second: (highlighted in the ticket description), when a page is set as the page_for_posts, is_singular() is false and the logic handling <!--nextpage--> is skipped entirely. Earlier in the process, the query object was populated with posts, so as far as handle_404() is concerned, is_home() is true and the page can be loaded as is. The fix for this seems a little more complicated and _could_ be handled earlier in the process.

Thanks for the detailed comment!

[47727] should fix the first item, let's keep the ticket open for the second item.

#6 @SergeyBiryukov
6 years ago

In 47738:

Query: Simplify the logic in WP::handle_404() to allow for easier modifications.

See #45337.

#7 @SergeyBiryukov
6 years ago

  • Milestone Future Release → 5.5
  • Owner set to SergeyBiryukov
  • Status new → accepted

#8 @SergeyBiryukov
6 years ago

  • Resolution → fixed
  • Status accepted → closed

In 47760:

Canonical: Redirect paged requests for a static page assigned as the "Posts page".

This avoids displaying duplicate content of the home page under different URLs with appended page numbers.

This change only affects the <!--nextpage--> pagination (page query variable) and not the regular multiple posts pagination (paged query variable).

The posts page does not support the <!--nextpage--> pagination, so requests for invalid page numbers should be redirected to the page permalink, applying the logic previously implemented for single posts or pages.

Follow-up to [34492], [47727].

Props jeremyfelt, sachit.tandukar, SergeyBiryukov.
Fixes #45337. See #40773, #28081, #11694.

#9 @SergeyBiryukov
6 years ago

In 47761:

Canonical: Only redirect non-existing page requests to the post permalink if the post is found.

Follow-up to [47760].

See #45337, #40773, #28081, #11694.

#10 @SergeyBiryukov
6 years ago

In 47781:

Tests: Give canonical test fixtures for paginated content more descriptive names.

Follow-up to [47727].

See #28081, #40773, #45337.

Note: See TracTickets for help on using tickets.