Doc WordPress WordPress Tricks, Tips & Snippets


Disable automatic redirect to site url

By default WordPress redirects incoming links automatically to the proper URL based on the site url, e.g. it would redirect incorrect incoming "www." URLs automatically to the correct form, as set in the site url setting. For example: when a requested URL is "" but the site-url is set as "" WordPress will automatically redirect the visitor to "".

This is a good thing as search engines consider www. and non-www. as different URLs and this would otherwise lead to duplicate content. But should you for whatever reason wish to disable this behaviour you can easily do so by just adding this snippet to your theme's function.php:

remove_action('template_redirect', 'redirect_canonical');

Please note: this will also disable canonical redirects!

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.