Handy WordPress URL re-write

This content is 12 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.