Make WordPress Core


Ignore:
Timestamp:
08/27/2020 01:35:31 AM (6 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.
Merges [48872] to the 5.5 branch.
Fixes #50910.

Location:
branches/5.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.5

  • branches/5.5/src/wp-includes/canonical.php

    r48586 r48873  
    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.