Make WordPress Core

Opened 6 years ago

Last modified 17 months ago

#51662 new defect (bug)

Pagination adds extra trailing slash at the end of some URLs

Reported by: thornsteps Owned by:
Priority: normal Milestone: Awaiting Review
Component: Rewrite Rules Version: 5.5.1
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

WordPress 5.5.1 pagination adds extra trailing slash at the end of some URLs.

Normally, our website's URLs don't have trailing slash at the end of the URL.

We have found some bug on the_posts_pagination() function on WordPress 5.5.1.

[At page 2 of a category]​https://stepstraining.co/strategy/page/2:
Previous link = ​https://stepstraining.co/strategy/
Page 1 link = ​https://stepstraining.co/strategy/

[At page 3 or more than page 3 of a category]​https://stepstraining.co/strategy/page/3:
Page 1 link = ​https://stepstraining.co/strategy/

All of the above URLs will 301 redirect to ​https://stepstraining.co/strategy --it should not have trailing slash at the end of the URL in the first place.

[At page 2 of a tag]​https://stepstraining.co/seo/page/2:
Previous link = ​https://stepstraining.co/seo/
Page 1 link = ​https://stepstraining.co/seo/

[At page 3 or more than page 3 of a tag]​https://stepstraining.co/seo/page/3:
Page 1 link = ​https://stepstraining.co/seo/

All of the above URLs will 301 redirect to ​https://stepstraining.co/seo --it should not have trailing slash at the end of the URL in the first place.

The bug was gone when we tested adding untrailingslashit() to below code:
File : /wp-includes/general-template.php
esc_url( apply_filters( 'paginate_links', untrailingslashit($link) ) ),

Attachments (1)

51662.jpg​ (369.7 KB ) - added by jignesh.nakrani 21 months ago.

Download all attachments as: .zip

Change History (9)

#1 follow-up: @lukecarbis
6 years ago

Is this a duplicate of #52057?

#2 in reply to: ↑ 1 @thornsteps
6 years ago

Replying to lukecarbis:

Is this a duplicate of #52057?

I think it's similar. I opened this ticket 2 months ago and still have this problem on WordPress 5.5.3 .

At first, we don't have this bug until one day we did SEO checking again and found it.

Last edited 6 years ago by thornsteps (previous) (diff)

#3 @kaderavek
6 years ago

#52057 was marked as a duplicate.

#4 @SergeyBiryukov
6 years ago

  • Summary WordPress 5.5.1 pagination adds extra trailing slash at the end of some URLs → Pagination adds extra trailing slash at the end of some URLs

Adjusting the title, as the issue is not specific to WordPress 5.5.1 and was likely introduced earlier.

#5 @djovanov
3 years ago

Same issue, reproduced on WordPress 6.22 and Twenty Twenty Two on fresh install, without plugin's.
Any workaround solution ?

This ticket was mentioned in ​PR #4684 on ​WordPress/wordpress-develop by ​@jignesh.nakrani.


3 years ago
#6

  • Keywords has-patch added

#7 @jignesh.nakrani
21 months ago

I tried to reproduce the issue In the latest clean setup with Twenty Twenty-Five, and no plugins were installed. It still exists.

#8 @djovanov
17 months ago

Fixed with this function php code :

add_filter( 'paginate_links', function( $link ) {
    // remove only trailing slash
    return preg_replace( '#(?<!:)/$#', '', $link );
});
Last edited 17 months ago by djovanov (previous) (diff)
Note: See TracTickets for help on using tickets.