Skip to content

Support Forums: Redirect paginated topic URLs to add the trailing slash - #1208

Open
dhrupo wants to merge 1 commit into
WordPress:trunkfrom
dhrupo:fix/5322-topic-page-trailing-slash
Open

dhrupo wants to merge 1 commit into
WordPress:trunkfrom
dhrupo:fix/5322-topic-page-trailing-slash

Conversation

@dhrupo

@dhrupo dhrupo commented Nov 8, 2026 •

Copy link
Copy Markdown

Fixes https://meta.trac.wordpress.org/ticket/5322

/support/topic/<slug>/page/2 (no trailing slash) returns a 200 instead of a 301 to /support/topic/<slug>/page/2/.

Core's redirect_canonical() would add the slash, but bbPress turns it off on paginated single topics: bbp_do_not_redirect_paginations() on the bbp_redirect_canonical filter returns an empty URL when bbp_get_paged() is above 1 on a single topic. So nothing adds the slash on page 2 and later. The topic URL itself and page 1 are already redirected.

This adds redirect_topic_page_trailing_slash() on bbp_template_redirect, next to redirect_page_zero_one(). On a paginated single topic it sends a 301 to the user_trailingslashit() form of the request path, with the query string kept. POST requests are left alone.

  • /topic/<slug>/page/2: 301 to /topic/<slug>/page/2/
  • /topic/<slug>/page/2?replies=1&foo=bar: 301 to /topic/<slug>/page/2/?replies=1&foo=bar
  • /topic/<slug>/page/2/: 200, unchanged

The Location header is the request path (relative), so it stays right under the /support/ site path.

Testing

  1. npm run support:env start in environments/. (On Docker Desktop this currently fails on the wporg-ratings.php mount; Environments: Fix jobs, WordPress.tv and Support Forums envs failing to start #1205 fixes that.)
  2. Create a topic with 20 replies, so it has 2 pages.
  3. curl -sI http://localhost:8888/topic/<slug>/page/2 shows 301 and Location: /topic/<slug>/page/2/.
  4. curl -sI http://localhost:8888/topic/<slug>/page/2/ shows 200.

A Playwright run against the local environment failed on trunk with Expected: 301 Received: 200 (3 failed, 1 passed) and passes with this change (4 passed).

AI assistance: Yes. Tool: Claude Code. Used for: finding the cause and drafting the change; I reviewed and tested it myself.

Summary by CodeRabbit

  • Bug Fixes
    • Paginated topic pages now use consistent trailing-slash URLs. Visitors arriving at older URL formats are redirected to the corresponding page, with query parameters preserved.

bbPress turns off redirect_canonical() on paginated single topics, so
/topic/<slug>/page/2 answered with a 200 instead of a redirect. Send a
301 to the user_trailingslashit() form of the path, keeping the query
string.

See https://meta.trac.wordpress.org/ticket/5322
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dhrupo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The plugin registers a redirect for paginated single-topic requests. For eligible requests, it adds the paged trailing-slash format to the path and issues a 301 redirect while preserving the query string.

Changes: Paginated topic redirect

Layer / File(s) Summary
Register and apply topic redirect
wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php
The constructor registers the redirect on bbp_template_redirect. For non-POST requests on single-topic pages numbered 2 or higher, the callback sanitizes the request URI and issues a 301 redirect if the formatted path changes. The redirect preserves the query string.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: jjj, obenland

Merge Risk: Minimal · up to f9cc3

The redirect appears mergeable after normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: paginated single-topic URLs without a trailing slash are redirected to the trailing-slash form. The raw summary confirms a new redirect_topic_page_trailing_slash() met…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: paginated single-topic URLs without a trailing slash are redirected to the trailing-slash form. The raw summary confirms a new redirect_topic_page_trailing_slash() method that issues a 301 for non-POST requests on topic pages numbered 2 or higher, preserves the query string, and is registered on bbp_template_redirect. The objectives describe the same behavior and the same ticket. The title is specific and matches the changeset.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 98f4a325-b729-4d0d-95ea-969f4291ce50
Commits

Reviewing files that changed from the base of the PR and between 82f0414 and f9cc361.

Files selected for processing: 1

  • wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant