Make WordPress Core


Ignore:
Timestamp:
09/25/2024 07:35:20 PM (3 months ago)
Author:
hellofromTonya
Message:

Canonical: Redirect when front page's paginated states not found.

Perform a canonical redirect for an invalid pagination request of a static front page.

When a site has a static front page assigned and that page has a <!--nextpage--> within its content, previously accessing non-existing pages (e.g. example.com/page/3/) did not redirect or return a 404 or 301. This changeset resolves that issue by performing a canonical redirect.

Unit tests are also included for this specific use case and to ensure the fix does not affect a blog listing home page.

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

Props dd32, audrasjb, chaion07, hellofromTonya, joemcgill, lukecarbis, Mte90, mukesh27, peterwilsoncc, rajinsharwar, SergeyBiryukov.
Fixes #50163.
See meta#5184.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp.php

    r56395 r59091  
    748748
    749749            if ( is_singular() ) {
    750                 $post = isset( $wp_query->post ) ? $wp_query->post : null;
    751                 $next = '<!--nextpage-->';
     750                $post    = isset( $wp_query->post ) ? $wp_query->post : null;
     751                $next    = '<!--nextpage-->';
     752                $page_qv = is_front_page() ? 'paged' : 'page';
    752753
    753754                // Check for paged content that exceeds the max number of pages.
    754                 if ( $post && ! empty( $this->query_vars['page'] ) ) {
     755                if ( $post && ! empty( $this->query_vars[ $page_qv ] ) ) {
    755756                    // Check if content is actually intended to be paged.
    756757                    if ( str_contains( $post->post_content, $next ) ) {
    757                         $page          = trim( $this->query_vars['page'], '/' );
     758                        $page          = trim( $this->query_vars[ $page_qv ], '/' );
    758759                        $content_found = (int) $page <= ( substr_count( $post->post_content, $next ) + 1 );
    759760                    } else {
Note: See TracChangeset for help on using the changeset viewer.