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 had a custom post type with slug as (sometext) which I changed to (someothertext) And it works great

So for example :

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.

share|improve this question

2 Answers 2

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.

share|improve this answer
    
hi Mike, thanks for your reply. I'm afraid it does not work. As i said in my question urls to my posts are getting redirected successfully but not for archive pages. (I already flushed rewrite rules by visiting Settings -> Permalinks) –  Kuldeep Daftary Jan 28 '13 at 11:08
    
Do you have the argument has_archive in the register_post_type function on true, or on sometext? It could it be that you'll have the archive manual directed to sometext? –  Mike Madern Jan 28 '13 at 11:21
    
yes mike 'has_archive' is set to true, and not set as sometext. I also tried changin 'has_archive' => 'someothertext' but still it returns 404 –  Kuldeep Daftary Jan 28 '13 at 11:52

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;
}
share|improve this answer

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.