[wp-trac] [WordPress Trac] #63544: Provide a way to switch off the redirect_canonical() function
WordPress Trac
noreply at wordpress.org
Sat Jun 7 13:47:26 UTC 2025
#63544: Provide a way to switch off the redirect_canonical() function
-------------------------+-----------------------------
Reporter: lowellj55 | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Canonical | Version: 6.8
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
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($_SERVER['REQUEST_URI'], '/roster/') === 0) {
return false;
}
return $redirect_url;
}, 10, 2);
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63544>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list