Permalink change redirects by WordPress

admin2025-06-05  1

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?

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?

Share Improve this question asked Nov 7, 2018 at 16:21 bikegremlinbikegremlin 18610 bronze badges 5
  • Are you sure you don't have a SEO plugin that automatically created the redirect? – kero Commented Nov 7, 2018 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 Commented Nov 7, 2018 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. – bikegremlin Commented Nov 7, 2018 at 16:54
  • Apparently, WordPress makes 302 redirects, according to this: moz/blog/… – bikegremlin Commented Nov 7, 2018 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 Commented Nov 8, 2018 at 3:52
Add a comment  | 

1 Answer 1

Reset to default 1

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749121301a316544.html

最新回复(0)