We have a WordPress site with a permalink structure like this:
news/%year%/%monthnum%/%day%/%postname%/
I noticed today that if I attempt to visit a non-exist page, WordPress will seemingly grab the first (?) post that is a partial match for that slug.
For example:
real: /news/2025/02/15/story-name
is a valid post page. But if the user attempts to go to
not real: /some/page/that/does/not/exist/story-name
It will resolve to the "real page" because the slug matches. Whats more, this will actually happen for a partial match like this:
not real: /some/page/that/does/not/exist/story
This is not the behavior I want. I noticed it because I was trying to use the template_redirect
action to catch and redirect some legacy URLs. One of those legacy URLs happens to end with story
so this re-direction was happening. It seemed to happen before the template_redirect
action.
What is going on here and how do I make WordPress bend to my will?
We have a WordPress site with a permalink structure like this:
news/%year%/%monthnum%/%day%/%postname%/
I noticed today that if I attempt to visit a non-exist page, WordPress will seemingly grab the first (?) post that is a partial match for that slug.
For example:
real: /news/2025/02/15/story-name
is a valid post page. But if the user attempts to go to
not real: /some/page/that/does/not/exist/story-name
It will resolve to the "real page" because the slug matches. Whats more, this will actually happen for a partial match like this:
not real: /some/page/that/does/not/exist/story
This is not the behavior I want. I noticed it because I was trying to use the template_redirect
action to catch and redirect some legacy URLs. One of those legacy URLs happens to end with story
so this re-direction was happening. It seemed to happen before the template_redirect
action.
What is going on here and how do I make WordPress bend to my will?
Share Improve this question asked Mar 18 at 20:23 ScribblemacherScribblemacher 1557 bronze badges 3 |1 Answer
Reset to default 1Looks like this was being caused by the redirect_guess_404_permalink()
function. To disable this behavior, I used:
add_filter( 'do_redirect_guess_404_permalink', '__return_false' );
redirect_guess_404_permalink()
, which I added as an answer for posterity (and/or for myself when I forget about this in 6 months). – Scribblemacher Commented Mar 19 at 18:22