Custom post types archive redirect

I had a custom post type with slug as (sometext) which I changed to (someothertext)
And it works great

So for example :

Read More

my posts with urls like

http://localhost/sometext/innerposts

gets redirected to

http://localhost/someothertext/innerposts 

but not my archive page

basically I would like to redirect

http://localhost/sometext/ to
http://localhost/someothertext/ 

in my .htaccess file
I tried adding a string to make it work

RewriteRule ^/sometext$ ^/someothertext/$ [R=301,L]

but it fails.

I’m very poor with .htaccess rewrites. I’ll really appreciate if someone helps me out with this.

Thanks.

Related posts

Leave a Reply

2 comments

  1. The link to the archive page is saved into WordPress rewrite rules. These rules are used to locate several locations on the front end of your WordPress system. When you change the slug of a Custom Post Type, the normal pages will redirect directly to the new location, but the archive page won’t, this because the rewrite rules aren’t regenerated.

    To solve this, go to Settings -> Permalinks and save your permalink structure again, reload your page and the archive page will load correctly.

    The rewrite rule in your .htaccess won’t be needed.

    Also, never put any rewrite rules in your .htaccess except the ones WordPress writes into it.
    If you want to add some rules, do this by using the Rewrite API.

  2. As it was mentioned. Never put any rewrite rules in your .htaccess, use Rewrite API instead. To reach your goal, use following code in your functions.php or site-specific plugin:

    add_action( 'generate_rewrite_rules', 'my_rewrite_rules' );
    function my_rewrite_rules( $wp_rewrite )
    {
        $wp_rewrite->rules = array(
            'sometext/(.+?)/?$' => $wp_rewrite->index . '?someothertext='.$wp_rewrite->preg_index( 1 ),     
            'sometext/(.+?)/([0-9]{1,})/?$' => $wp_rewrite->index . '?someothertext='.$wp_rewrite->preg_index( 1 ). '&paged=' . $wp_rewrite->preg_index( 2 ),               
        ) + $wp_rewrite->rules;
    }