Whenever I type a url for my site that contains three slashes "/" wordpress shows the front page instead of a 404.For example: example.com/something/does/notexist goes to frontpage, where example.com/something/doesnotexist/ correctly shows a 404.

I added several debug tools to see what's happening. The rewrite rule explorer shows that no rule matched the request. Yet the front page is loaded. I assume this is related to pagination requests like /something/page/3. What I don't understand is why wordpress does not actually do the query to see that nothing is there and therefore throw a 404? I already disabled all plugins and the theme's functions.php. Still the same behaviour. I find this issue sometimes on my life site but always on my local installation that runs valet. I can not see how this is a server issue though, as wordpress itself says "no rule matched" but then goes to the frontpage anyway. I have searched for days now but can not find anything. Most related problems are the other way around, where a pagination link shows 404 when it shouldn't. Any help is appreciated.

PS: I did flush rewrite rules multiple times, nothing changed.

Edit: I think I should make the url structure a little clearer:

example.com/a/b/c -> Goes to Frontpage (should do 404)
example.com/a/b/ -> Shows 404

It does not matter at all what I type in the url. As soon as there is three slashes with anything behind the last one, it always shows the frontpage.

Edit 2: I tried running the site with wp server and it now correctly shows the 404 page for both urls. However, what is strange (and probably somehow related) is that for this type of url example.com/a/b/c wordpress makes an additional query after the get_page_by_path() returns no page found.

FROM wp_posts
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'acf-disabled'
OR wp_posts.post_status = 'private')
ORDER BY wp_posts.post_date DESC
LIMIT 0, 11

This then becomes the Main Query. I can see the 404 page, but the posts property is populated, which has a lot of side effects for other hooks on the page. It does not do this query when the url is just example.com/a/b/. Then wordpress just does to query the 404 page and that's the end of it.

  • 1
    Is this really happening with all URLs with 3 slashes, or just page URLs with a number on the end? Jan 10, 2022 at 13:37
  • Hi, I should have been clearer. It is not the slashes itself. As soon as there is anything after the third slash, it goes to the front page. If the url ends with the third slash and nothing after it, it correctly goes to 404 not found.
    – mrks.diehl
    Jan 10, 2022 at 13:43
  • 1
    Have you already tried switching to a default theme, e.g. Twenty Twenty-One, and did the same issue persist? What's in your .htaccess file and what is your permalink structure?
    – Sally CJ
    Jan 10, 2022 at 14:42
  • I switched to default theme with the same result. No .htaccess is used. The site runs on my local environment with valet. Your comment made me curious, though. So I ran the php server with wp server to see if the problem occurs here, too. It does not. I still do not know what is happening, but I am one step closer at least. The site still behaves differently with anything after the third slash, but at least I can see a 404 now. Will keep investigating. Thank you for the comment.
    – mrks.diehl
    Jan 10, 2022 at 15:40
  • Then I guess it's something specific to your server or Valet/Nginx setup? And I don't use Valet, but you might find something that helps here.
    – Sally CJ
    Jan 11, 2022 at 1:30


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy