Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 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 Owned by:
Priority: normal Milestone:
Component: Sitemaps Version:
Severity: normal Keywords:
Cc: Focuses:

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
6 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' );
}
Version 0, edited 6 years ago by GamerZ (next)

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

  • Resolution → duplicate
  • Status new → closed

Duplicate of #50910.

#4 @SergeyBiryukov
6 years ago

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