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.
Yes it does. If you change a post slug, wordpress 301 redirects the old to the new URL (if your server setup allows it).
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.