Support » Fixing WordPress » 301 Redirect Problem

  • I removed a ‘native and aboriginal news’ category along with all it’s posts from my website – ‘’ to a new domain – ‘’. I changed my permalink structure, search engines indexed the new change and then stupidly I changed it again to the structure I really wanted.

    Anyway… I currently have this in my header.php to do 301 redirects. I can’t delete the posts in the ‘native and aboriginal news’ category from my site ( because the redirects won’t work – the following php only works when the posts is on the source and the destination server.

    Does anyone know of a way I can do this without needing the posts to exist on the old server?

    $category = get_the_category();
    $categoryname = $category[0]->cat_name;
    $categoryslug = $category[0]->category_nicename;
    $postslug = $post->post_name;
    if( $categoryslug == 'native-and-aboriginal-news' && is_single() ) { ?>
      header("HTTP/1.1 301 Moved Permanently");
    ?><?php } else { ?><? 
    $url = 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
    if( is_single() && $url != "$categoryslug/$postslug/" ) {
      header("HTTP/1.1 301 Moved Permanently");
    ?><?php } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Easier to setup redirects with a plugin such as this:

    I *think* this plugin should do what you would like to do in an easy to manage fashion – but don’t quote me! It certainly works for managing permalink structure changes. Since you have already changed your permalink structure though, I would suggest changing it back to what the search engines are familiar with, enabling the plugin, and then changing the structure back to how you would like it to be.

    Let me know if this helps for your site change too.

    That php I put in there essentially does what the plugin you posted mentioned. I’d installed that before, but it doesn’t work if the posts are on a different domain altogether and don’t exist on the source domain.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘301 Redirect Problem’ is closed to new replies.