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?
This question already has answers here: Changing pemalink structure to /%post_id%/%postname%/ (2 answers) Closed 6 years ago.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?
I think I got it. Made a test site. With permalink structure:
year/moth/day/postname.
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/2018/11/04/hello-world/ from my browser:
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/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/postID (with or without trailing slash) and the browser goes to example/postID/ (with a trailing slash) directly, showing the contents of example/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
redirect_guess_404_permalink
, you can look in the source code and see what it does. – Milo Commented Nov 7, 2018 at 16:50