This question is an exact duplicate of:

Interesting thing I tried on a test site: I switched permalink structure from date/postname to postID/postname. From WordPress Permalinks panel - no plugins, no .htaccess entries, nothing, just switched permalink structure. Then tried old post links, using the date/postname link. They were automatically redirected to the new address (postID/postname). I see no changes to .htaccess (made by WordPress).

Any idea how WordPress implements this? Does it affect performance?

marked as duplicate by Jack Johansson Nov 8 '18 at 16:25

This question was marked as an exact duplicate of an existing question.

  • Are you sure you don't have a SEO plugin that automatically created the redirect? – kero Nov 7 '18 at 16:29
  • 1
    The function that does this is redirect_guess_404_permalink, you can look in the source code and see what it does. – Milo Nov 7 '18 at 16:50
  • No plugins for SEO, it was tested on a test site - so few posts and pages, for testing and that's it. – Relja Novović Nov 7 '18 at 16:54
  • Apparently, WordPress makes 302 redirects, according to this: moz.com/blog/… – Relja Novović Nov 7 '18 at 17:36
  • @ReljaNovović that post is almost 6 years old, I don't think WP does any 302 redirects any more. When I test my local install, all I see are 301s. – Milo Nov 8 '18 at 3:52

I think I got it. Made a test site. With permalink structure:


Published a post. Then changed permalinks to postID/post-name. Tested with looking at network stats from the browser. Here's what I got, a 301 redirect, after trying example.com/2018/11/04/hello-world/ from my browser:

what the browser does

I tested another thing. Using different permalink structures, I tried to make two posts with the same post-name (the link part where post-name is). WordPress won't allow it.

My conclusion is that post-name and postID are both unique. This would explain why this auto-301 redirect works, as well as why having a flat directory structure of example.com/post-name isn't so slow performing, as it was before WordPress 3.3. (I think) version.

Another interesting thing is that, using permalink structure of postID/post-name, I can enter in a browser: example.com/postID (with or without trailing slash) and the browser goes to example.com/postID/ (with a trailing slash) directly, showing the contents of example.com/postID/post-name.

So this seems to be nicely sorted out, no need to worry about manually setting 301 redirects, either with .htaccess entries (my planned change would have required manual redirect for each post, since I'm adding a unique ID in the link structure). No need for plugins as well.

What needs to be done is change all the internal links - WordPress doesn't automatically change them. It does 301 redirects, but the old links remain. That's a bother.

EDIT: after a month on a live site, wrote in detail about results, how the redirect is made, how I tested: WordPress permalink change

  • Keep in mind that this sort of redirection is a guess, it uses a LIKE query and is not an exact match, so it can and will occasionally redirect to the wrong post if slugs are similar. – Milo Nov 8 '18 at 15:53
  • Are you certain? Postnames of (up to date) WordPress are unique. So I don't see why redirect would not be accurate. Could you explain? – Relja Novović Nov 8 '18 at 16:18
  • I understand it wouldn't be able to figure out any "exotic" url additions (though it seems to recognize and keep the correct # links with no problems), but for most it should just look up the post-name in the database and redirect to the "new" link with the same postID that the post-name has. It can't cope with anchor (#) link additions containing spaces (blanks). But all the other combinations seem to work. – Relja Novović Nov 8 '18 at 16:44
  • It doesn't query for an exact match. about can redirect to about-us, because it simply contains about, but it's not a 1-to-1 match. – Milo Nov 8 '18 at 17:08
  • It seems so - WHEN there is no matching page-name, then it tries the guessing. However, as long as the old link is a proper/working one, containing the page-name (or postID), it works flawless. I'm not expecting it to fix broken links. Just to keep the good ones working - and it does exactly that. – Relja Novović Nov 8 '18 at 17:50

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