Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I recently noticed that Wordpress tries to auto-complete a URL when it's not submitted in its entirety. E.g. I have a post URL that looks like this:

http://www.mysite.com/some-post-title

If I browse to the following URL:

http://www.mysite.com/some-post-ti

I can see that the URL is submitted to Wordpress but that Wordpress is doing a 301 redirect to http://www.mysite.com/some-post-title.

How can I disable this behavior?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

I believe that is the redirect_canonical function hooked to template_redirect. You should be able to disable it with:

remove_filter('template_redirect', 'redirect_canonical'); 

But you should really think about whether you want to do that as it is fairly complicated and performs some important SEO functions:

Redirects incoming links to the proper URL based on the site url.

Search engines consider www.somedomain.com and somedomain.com to be two different URLs when they both go to the same location. This SEO enhancement prevents penalty for duplicate content by redirecting all incoming links to one or the other.

Prevents redirection for feeds, trackbacks, searches, comment popup, and admin URLs. Does not redirect on non-pretty-permalink-supporting IIS 7, page/post previews, WP admin, Trackbacks, robots.txt, searches, or on POST requests.

Will also attempt to find the correct link when a user enters a URL that does not exist based on exact WordPress query. Will instead try to parse the URL or query in an attempt to figure the correct page to go to.

http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/canonical.php#L13

The following might kill the autocompletion without messing with the SEO component, but I can't promise that. The code is barely tested as I have never wished to disable this. I'd really have to study redirect_canonical to be sure of anything.

function kill_404_redirect_wpse_92103() {
  if (is_404()) {
   add_action('redirect_canonical','__return_false');
  }
}
add_action('template_redirect','kill_404_redirect_wpse_92103',1);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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