url rewriting - Does WordPress keep track of a post's URL history and provide automatic redirects?

admin2025-01-07  4

I just changed the URL of one of my posts from

/

to

/

Now, if I go to the old url, I get redirected to the new one. This is great of course!
...But is this a feature of WordPress, or what's going on here?

Does WP keep track of a post's URL history, providing rewrites/redirects for former URLs?
Looking at the response header I see WP is sending out a SEO friendly 301 redirect... Yes!?
I thought I'd have to set up those redirects using rewrite rules in my .htaccess, so I'm curious to know how it happens that WP is giving me my new URL when I type in the old one.

Any light on how WP handles this would be appreciated.

I just changed the URL of one of my posts from

http://2011.denmark.wordcamp.org/session/theme-frameworks-trends-og-standardisering/

to

http://2011.denmark.wordcamp.org/session/wordpress-themes-mere-end-design/

Now, if I go to the old url, I get redirected to the new one. This is great of course!
...But is this a feature of WordPress, or what's going on here?

Does WP keep track of a post's URL history, providing rewrites/redirects for former URLs?
Looking at the response header I see WP is sending out a SEO friendly 301 redirect... Yes!?
I thought I'd have to set up those redirects using rewrite rules in my .htaccess, so I'm curious to know how it happens that WP is giving me my new URL when I type in the old one.

Any light on how WP handles this would be appreciated.

Share Improve this question edited Mar 29, 2013 at 19:54 Johannes Pille 11.1k3 gold badges42 silver badges53 bronze badges asked Nov 9, 2011 at 22:18 mikkelbreummikkelbreum 2,4765 gold badges28 silver badges34 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 22

Does WP keep track of a posts url history, providing rewrites/redirects for former urls?

Yes it does. If you change a post slug, wordpress 301 redirects the old to the new URL (if your server setup allows it).

Any light on how WP handles this would be appreciated.

Unfortunately, I've never seen this feature properly documented in the codex. Hence I cannot tell you which wp core function does this and where in the core it is located.

What I can tell you though is this: The previously used slug(s) are stored in the database in the wp_postmeta table. Check for _wp_old_slug in the meta_key column (the actual slugs being stored in the meta_value column). Hence should you ever want this default behavior not to happen in a particular case, this is where to delete a value.

More often than not this feature is very helpful. It screws up though, when you rename a post and later on create a new post with the same name the other one had had earlier.

At least with current WordPress (v6.7) the wp_old_slug_redirect function is called on the 'template_redirect' hook.

It only works on "non-hierarchical" post types though, so not for pages!

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

最新回复(0)