Make WordPress Core


Ignore:
Timestamp:
05/04/2020 10:40:06 AM (5 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/canonical/paged.php

    r46586 r47760  
    77class Tests_Canonical_Paged extends WP_Canonical_UnitTestCase {
    88
    9     function test_nextpage() {
     9    function test_redirect_canonical_with_nextpage_pagination() {
    1010        $para = 'This is a paragraph.
    1111            This is a paragraph.
     
    2020        );
    2121
    22         $link  = parse_url( get_permalink( $post_id ), PHP_URL_PATH );
    23         $paged = $link . '4/';
     22        $link = parse_url( get_permalink( $post_id ), PHP_URL_PATH );
    2423
    25         $this->assertCanonical( $paged, $link );
     24        // Existing page should be displayed as is.
     25        $this->assertCanonical( $link . '3/', $link . '3/' );
     26        // Non-existing page should redirect to the permalink.
     27        $this->assertCanonical( $link . '4/', $link );
    2628    }
     29
    2730}
Note: See TracChangeset for help on using the changeset viewer.