WordPress.org

Ready to get started?Download WordPress

Forums

301 Redirect Problem (3 posts)

  1. Ryan Paul
    Member
    Posted 5 years ago #

    I removed a 'native and aboriginal news' category along with all it's posts from my website - 'www.ryanpaul.ca' to a new domain - 'www.intertribaltimes.ca'. 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 (ryanpaul.ca) 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?

    <?php
    $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() ) { ?>
    <?php
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: http://www.intertribaltimes.ca/native-and-aboriginal-news/$postslug");
    ?><?php } else { ?><? 
    
    $url = 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
    if( is_single() && $url != "http://www.ryanpaul.ca/$categoryslug/$postslug/" ) {
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: http://www.ryanpaul.ca/$categoryslug/$postslug/");
    }
    
    ?><?php } ?>
  2. flammobammo
    Member
    Posted 5 years ago #

    Easier to setup redirects with a plugin such as this:
    http://urbangiraffe.com/plugins/redirection/

    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.

  3. Ryan Paul
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic