Make WordPress Core

#63544 closed enhancement (wontfix)

Provide a way to switch off the redirect_canonical() function

Reported by: lowellj55 Owned by:
Priority: normal Milestone:
Component: Canonical Version:
Severity: normal Keywords:
Cc: Focuses:

Description

I intentionally deprecated a page on the website. Subsequently, Google Search Console reported a soft 404 error on that page. The reason is that WordPress was redirecting to a different, unrelated page. I had to add code to function.php to prevent the redirect. An administrator should be able to turn the redirect function on or off.

Problem:
Requests for url ​https://mnbreakfast.org/roster/
Are being redirected to ​https://mnbreakfast.org/rosterresponse/

curl -I ​https://mnbreakfast.org/roster/

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-WS-RateLimit-Limit: 1000
X-WS-RateLimit-Remaining: 999
Date: Wed, 28 May 2025 16:32:36 GMT
Server: Apache
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0, no-store, private
X-Redirect-By: WordPress
Location: ​https://mnbreakfast.org/rosterresponse/

Here's What’s Likely Happening:
When a user (or Googlebot) requests a non-existent URL like /roster/, WordPress guesses you meant /rosterresponse/ and automatically 301 redirects to it — especially if:

  • The slugs are similar
  • There is no /roster/ page (published, draft, or trashed)

This behavior is part of WordPress's redirect_canonical() function.

Added this snippet to functions.php
add_filter('redirect_canonical', function($redirect_url, $requested_url) {

if (strpos($_SERVERREQUEST_URI, '/roster/') === 0) {

return false;

}
return $redirect_url;

}, 10, 2);

Change History (1)

#1 @jorbin
17 months ago

  • Milestone Awaiting Review
  • Resolution → wontfix
  • Status new → closed
  • Version 6.8

Hi @lowellj55, welcome to WordPress Trac.

WordPress has a philosohphy of ​Decisions, not Options becouse

Every time you give a user an option, you are asking them to make a decision. When a user doesn’t care or understand the option this ultimately leads to frustration. As developers we sometimes feel that providing options for everything is a good thing, you can never have too many choices, right? Ultimately these choices end up being technical ones, choices that the average end user has no interest in.

Rather than user facing options, WordPress has hooks (like the one you used in this situation) so that these rare cases can be solved without adding options that are unnecessary for the majority of users. As such, I am closing this as wontfix.

Note: See TracTickets for help on using tickets.