Last week, I accidentally advertised a blog post using two different URLs (I edited the title, which changed the WordPress slug, but forgot to edit a draft email to refer the new URL). With Twitter advertising one URL to potential customers, and our internal newsletter advertising another, I needed both to work.
I don’t have access to the server (only to the WordPress application), so playing around with IIS/Apache URL re-writes wasn’t an option. I started to look for WordPress plugins but couldn’t find any – and then I found out why…
Although there is no mention of it in the Codex, when you change the title of a post, WordPress automatically creates an HTTP 301 redirect from the the old URL to the new. I’ve seen this on my own blog but Johannes Pille describes it beautifully on StackExchange:
“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.”
I also found that the URL (and hence the slug) is not set until the post is published. I had edited the title whilst the post was in a scheduled state, so there was only one slug recorded (the new title). By editing the slug post-publish, I was able to prevent the HTTP 404s that some people were seeing.