Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#50926 closed defect (bug) (duplicate)

Page 2 onwards of any wp-sitemap.xml URL will result in a 404 redirect

Reported by: gamerz's profile GamerZ Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Sitemaps Keywords:
Focuses: Cc:

Description

Works: https://lesterchan.net/wp-sitemap-posts-page-1.xml
Broken: https://lesterchan.net/wp-sitemap-posts-page-2.xml

Notice that the broken URL is redirected to https://lesterchan.net/wp-sitemap-posts-page-2.xml/page/2

I suspect it is due to Line 475 to Line 477 of wp-includes/canonical.php

As after removing the lines it works

<?php
if ( $paged > 1 ) {
    $addl_path .= user_trailingslashit( "$wp_rewrite->pagination_base/$paged", 'paged' );
}

Change History (4)

#1 in reply to: ↑ description @GamerZ
5 years ago

Works: https://lesterchan.net/wp-sitemap-posts-post-1.xml
Broken: https://lesterchan.net/wp-sitemap-posts-post-2.xml

Works: https://lesterchan.net/wp-sitemap-taxonomies-post_tag-1.xml
Broken: https://lesterchan.net/wp-sitemap-taxonomies-post_tag-2.xml

Replying to GamerZ:

Works: https://lesterchan.net/wp-sitemap-posts-page-1.xml
Broken: https://lesterchan.net/wp-sitemap-posts-page-2.xml

Notice that the broken URL is redirected to https://lesterchan.net/wp-sitemap-posts-page-2.xml/page/2

I suspect it is due to Line 475 to Line 477 of wp-includes/canonical.php

As after removing the lines it works

<?php
if ( $paged > 1 ) {
    $addl_path .= user_trailingslashit( "$wp_rewrite->pagination_base/$paged", 'paged' );
}
Last edited 5 years ago by GamerZ (previous) (diff)

#2 @GamerZ
5 years ago

I have fixed it on my site by using redirect_canonical filter.

<?php
function lesterchan_redirect_canonical( string $redirect_url, string $requested_url ) {
        if ( strpos( $requested_url, 'wp-sitemap' ) !== false ) {
                return $requested_url;
        }

        return $redirect_url;
}
add_filter( 'redirect_canonical', 'lesterchan_redirect_canonical', 10, 2 );

#3 @GamerZ
5 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #50910.

#4 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.