Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
I edited the post to include your comment, you can remove the comment if you think it is unnecessary. –  Jan Fabry Jul 11 '11 at 15:56
    
anytime I add an .htaccess file the Wordpress pretty URLs no longer work. I cannot find a Wordpress generated .htaccess file anywhere on my development server. Any ideas? Anyone? Thanx –  dkmojo Jul 13 '11 at 15:18

4 Answers 4

up vote 0 down vote accepted

All you need to do is add a line like:

RewriteRule ^aboutus$ /about-us [R=301,L]

In to your .htaccess file. The old url should go between the ^ and $ and then new url after the slash.

share|improve this answer
    
how can I tell if the redirect 301 is active? That the redirect happened and not just a rewrite? Thanx –  dkmojo Jul 13 '11 at 15:47
    
you can use a tool like Firebug to watch the Network communication when you request a URL. That rule in the .htaccess will respond with a 301 header. –  Alex Older Jul 14 '11 at 7:17
    
cool thanx. I'll check on the redirect header in firebug –  dkmojo Jul 15 '11 at 13:14
    
Yep, it's all good! Thanx again –  dkmojo Jul 15 '11 at 13:24

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.

share|improve this answer
    
I actually changed the post type name. so the underlying URLS are different with the new version of my site. My original post was edited to clarify my question. Thanx again. –  dkmojo Jul 13 '11 at 13:31

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

share|improve this answer

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.

// The filter name is [post type name]_rewrite_rules, so I assume your post type name (not rewrite slug) is `designer`
add_filter( 'designer_rewrite_rules', 'wpse22625_designer_rewrite_rules' );
function wpse22625_designer_rewrite_rules( $rules )
{
    $old_rules = array();
    foreach ( $rules as $pattern => $substitution ) {
        $old_pattern = str_replace( 'designer', 'designer_lingerie', $pattern );
        $old_rules[$old_pattern] = $substitution;
    }
    return $rules + $old_rules;
}

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 into redirect_canonical, or by setting an extra flag that you check yourself.

share|improve this answer
    
My old post types no longer exist so would this work for me? I am not sure the benefits of this method. What would the benefit of not using Apache be? Just curiuos, Thanx –  dkmojo Jul 15 '11 at 13:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.