WordPress.org

Make WordPress Core

Opened 7 months ago

Closed 7 months ago

Last modified 7 months ago

#50926 closed defect (bug) (duplicate)

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

Reported by: 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
7 months 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 7 months ago by GamerZ (previous) (diff)

#2 @GamerZ
7 months 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
7 months ago

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

Duplicate of #50910.

#4 @SergeyBiryukov
7 months ago

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