Bug with redirect_canonical() for valid URLs matching /tag/(rss2?|feed|rdf|atom)/(.+)

I think I accidentally discovered a bug in ClassicPress (and WordPress) but I’m having difficulty making a replicable test case in a development environment and would appreciate the thoughts of anybody with better familiarity with the relevant code.

Summary: redirect_canonical() mistakes term slugs that look like feed endings (e.g. /tag/rss) and strips them, resulting in unwanted redirection.

Observed on:

  • my own ClassicPress 2.7.3 site with /2026/10/15/sample-post/-style permalinks
  • a fresh WordPress.com-hosted WordPress site

Not yet found a way to replicate on:

  • a fresh development copy of the develop branch of ClassicPress
  • a fresh copy of wordpress-develop

Steps to reproduce:

  1. Create a tag called rss (or feed, or rss2, or rdf, or atom).
  2. Create posts with that tag.
  3. :white_check_mark: Visit /tag/rss - works fine.
  4. :cross_mark: Visit /tag/rss/page/2 - should show the second page of posts with that tag; instead redirects to /tag/page/2/
  5. :cross_mark: Visit /tag/rss/feed - should show the RSS feed of posts with that tag; instead redirects to /tag/feed

I’ve successfully mitigated it in my theme like this:

function q26_no_canonical_for_feedlike_terms( $redirect_url ) {
  if ( ! ( is_tag() || is_category() || is_tax() ) ) return $redirect_url;
  $term = get_queried_object();
  if ( isset( $term->slug ) && preg_match( '/^(feed|rss2?|rdf|atom)$/', $term->slug ) ) return false;
  return $redirect_url;
}
add_filter( 'redirect_canonical', 'q26_no_canonical_for_feedlike_terms' );

But I feel like there must be a core issue here. I’ll continue trying to replicate it on a development system, but if anybody’s got any bright ideas I’d love to hear them!

I’ve successfully replicated it on the develop branch on ClassicPress.

Turns out canonical redirects are disabled when you run on unusual ports. My dev server was running on port :8080, which suppressed the bug. Switching my dev server to port :80 made it possible to replicate.

I’ll raise an issue in GitHub and, possibly, adapt my mitigation/workaround into an actual fix backed with tests and whatnot.

Okay, raised my first CP issue (#2746) and PR (#2747). Will keep an eye on the CI and tweak if needed, but it ought to pass the tests.

Looking forward to a review. Please be gentle, I’m kinda-new to your repo!

Thanks very much for this! I have seen your Issue and PR on Github and will test it over the next week or so; I’m sure others will too.