Make WordPress Core


Ignore:
Timestamp:
08/27/2020 01:28:24 AM (3 years ago)
Author:
peterwilsoncc
Message:

Sitemaps: Prevent incorrect redirection of paged sitemap requests.

Update redirect_canonical() to account for custom pagination and URL format used by sitemaps in order to follow standard practices.

Introduce the function get_sitemap_url() to simplify getting the index and provider URLs as needed.

Props jonathanstegall, pbiron, GamerZ, salvoaranzulla, peterwilsoncc.
Fixes #50910.

File:
1 edited

Legend:

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

    r48586 r48872  
    411411        }
    412412
    413         // Paging and feeds.
    414         if ( get_query_var( 'paged' ) || is_feed() || get_query_var( 'cpage' ) ) {
     413        if ( get_query_var( 'sitemap' ) ) {
     414            $redirect_url      = get_sitemap_url( get_query_var( 'sitemap' ), get_query_var( 'sitemap-subtype' ), get_query_var( 'paged' ) );
     415            $redirect['query'] = remove_query_arg( array( 'sitemap', 'sitemap-subtype', 'paged' ), $redirect['query'] );
     416        } elseif ( get_query_var( 'paged' ) || is_feed() || get_query_var( 'cpage' ) ) {
     417            // Paging and feeds.
    415418            $paged = get_query_var( 'paged' );
    416419            $feed  = get_query_var( 'feed' );
     
    507510            if ( ! empty( $addl_path ) ) {
    508511                $redirect['path'] = trailingslashit( $redirect['path'] ) . $addl_path;
    509             }
    510 
    511             // Remove trailing slash for sitemaps requests.
    512             if ( ! empty( get_query_var( 'sitemap' ) ) ) {
    513                 $redirect['path'] = untrailingslashit( $redirect['path'] );
    514512            }
    515513
Note: See TracChangeset for help on using the changeset viewer.