Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop WordPress from automatically doing a redirect?

I have a site running on WordPress, and it will automatically redirects URLs it thinks are written incorrectly.

For example, if I go to a URL that doesn't exist. Like this one:

www.example.com/blah-blah/my-page-slug/

will redirect me to...

www.example.com/my-page-slug/

How can I stop this redirection? I want to generate a 404 error if the wrong URL is typed in, not redirect.

like image 916
Chucky Cheese Avatar asked Oct 18 '25 14:10

Chucky Cheese


1 Answers

Place this in your theme's functions.php file.

remove_action('template_redirect', 'redirect_canonical');
like image 62
Ben Turner Avatar answered Oct 20 '25 17:10

Ben Turner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!