I changed the name of two of my custom post types. The original slugs for them did not properly reflect the post type. So I need to redirect requests for posts beginning with designer_lingerie
(the old post type slug) to just designer
. All of the posts are the same just the post type slug has changed.
I am sure I’ll need to use .htaccess
but am unsure of what to tell it to change. Basically what URL should I use to do this? The WordPress pretty URL or the default URL?
All you need to do is add a line like:
In to your .htaccess file. The old url should go between the ^ and $ and then new url after the slash.
I would not use the Apache Rewrite module, but the built-in WordPress rewrite functionality. If you want to see the rules it uses, install my Rewrite analyzer plugin. You can just duplicate the rules of your post type, with the old slug instead of the new slug. This way both URLs will link to your post content.
This will not generate a redirect – weird, I expected the
redirect_canonical()
function to do this. You can do it yourself if you want, either by hooking intoredirect_canonical
, or by setting an extra flag that you check yourself.If you change the permalinks but not the underlying structure WordPress should be able to find your posts, since the ‘real’ url structure is still the same. In other words if you only change the permalinks it should automatically redirect to the right location.
WP retains the corresponding metadata regarding the original non-pretty permalink and any changes to standard permalinks. See http://codex.wordpress.org/Using_Permalinks
If you have non-pretty permalinks in post/page content or leave them hardcoded anywhere, WP will redirect those to the pretty version.
That said, if you change the URL directly in the post/page editor, you do need to redirect. One of the ways to handle that is with a plugin like WordPress ⺠Redirection « WordPress Plugins