A
A
AlexSSS2015-10-29 09:06:56
WordPress
AlexSSS, 2015-10-29 09:06:56

How to make Wordpress always get 404 error?

Good afternoon!
Wordpress question. This is the first time I've encountered him, but I can't understand why he always redirects to similar pages. I'll give you an example. There is a link like site.ru/12345
If I open site.ru/1234, then site.ru/12345 is forcibly opened
If I open site.ru/123, then site.ru/12345 is forcibly opened
...
the engine looks for similar entries and substitutes a similar one, but due to the requirements for the site, this option does not suit.
How to solve this problem and force the engine to open only the page where I exactly entered its name? If the error is in at least one character, the code is 404.
Plugins include All in One SEO Pack, Cyr to Lat enhanced.
In the permalink settings is: /%year%/%postname%/
Thanks in advance for any help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2015-10-29
@mr_ko

Just dealt with this yesterday. Only such a situation arose on pages and posts (you most likely have a static page as the title), site.ru/post_slug/1234 it returns the page site.ru/post_slug. This situation is possible because WordPress has the ability to break a long post / pages into subpages and the numbers after the slash is pagination.
The problem was solved in this way:

add_action('template_redirect', 'test_redirect');
function test_redirect() {
  global $page, $wp_query;
  
    if(is_singular()) {
      if($page > 0) {
        $wp_query->set_404();
        wp_redirect( '/', 404 );

      }
    }
}

True, in this case, the site.ru/post_slug/0 address skips, but you can add another url check, but we didn’t bother with that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question