Wordpress has a feature whereby it will automatically redirect your URLs if it percieves them to be written wrongly. Here is an example: I have a page called my-page

If I go to:


it will immediately redirect me to


as nothing exists at the first URL.

How can I turn this feature off, and instead just get a 404 if incorrect URL's are typed in?

  • If you watch what is happening (via HttpFox or WireShark or a similar packet sniffer), those pages redirect with a 301 Status-- Moved Permanently-- which is appropriate behavior. It helps search engines keep their databases up to date among other things, and the redirect helps users find pages. This may effect how WordPress handles things when you actually do move a page or change a permalink, so be careful. Anyway, your choice but I am not sure it is a good idea.
    – s_ha_dum
    Nov 8, 2012 at 15:04
  • I know it's a good thing, I do understand that. However, I have a particular use case where I did not need that behaviour. I am developing a plugin which handles URL redirection and so I want to override that behavior.
    – Mazatec
    Nov 9, 2012 at 11:28
  • Here is a more correct answer: link Dec 19, 2014 at 10:54

3 Answers 3


This worked for me:

remove_action('template_redirect', 'redirect_canonical');
  • Can you guide me for what it will do? what is canonical redirect? i am new to wordpress Sep 25, 2014 at 7:50
  • You just saved me a lot of headaches! thank you ! :-D
    – Jenski
    Feb 26, 2016 at 10:34
  • 1
    Is there nowhere where we can see these redirects so that we can remove them on a one by one basis? Feb 22, 2017 at 13:50
  • This is great. Do you know why wp-admin might still be redirecting after using this?
    – Gezim
    Feb 3, 2018 at 13:56
  • You can find a detailed explanation of this issue at dev4press.com/blog/wordpress/2015/…
    – ronnefeldt
    Jan 14, 2019 at 5:33

As Ash suggested, you can turn off the feature by using the following code:

remove_action('template_redirect', 'redirect_canonical');

In looking at the redirect_canonical function in canonical.php, it would appear you can also modify the behavior with your own filter.

At the end of the redirect_canonical() function, there is a call to filter the final answer:

$redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url );

So you could write your own filter to modify the final redirection or return null to stop the redirection, based upon the input, thus turning off the feature for a particular URL or a subset of URLs.

  • This SO shows more details on how to add a filter for those like myself who are a bit new to WP Jan 30, 2020 at 21:22

You can disable permalink guessing for 404s without disabling redirection of canonical URLs by adding the following line somewhere in your code (eg. in functions.php):

add_filter('do_redirect_guess_404_permalink', '__return_false');

Relevant functions in the Wordpress code are redirect_canonical and redirect_guess_404_permalink in wp-includes/canonical.php.

  • Interestingly the docs seem outdated, because it says redirect_canonical is for both TLD-level redirects and also for 404 error redirects... Sep 24, 2020 at 16:23
  • 1
    @JesseNickles, Yes, redirect_canonical calls redirect_guess_404_permalink if the page is a 404, but it does other redirects as well. Sep 24, 2020 at 17:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.