Support » Fixing WordPress » How to generate 301 error for moved page?

  • I have a very basic Page.php template:

    <?php get_header(); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
         <div class="post" id="post-<?php the_ID(); ?>">
              <h2><?php the_title(); ?></h2>
              <div class="entry">
                   <?php the_content(); ?>
         <?php endwhile; ?>
         <?php edit_post_link('Edit', '<p>', '</p>'); ?>
         <?php else : ?>
         <h2>Not found</h2>
    <?php endif; ?>
    <?php get_footer(); ?>

    I recently moved some Pages that search engines are still generating links to. Is there a wordpress template tag I can use to replace the “Not found” message with a HTTP 301 Moved Permanently error?

    Or do I have to write code to identify the page_id of the moved page and use the PHP header() function?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I tried this…

    $pid = trim($_GET['page_id']);
    if ($pid = 362)
         header("HTTP/1.1 301 Moved Permanently");

    but received error: “Can’t rewrite headers… already set”

    I’ve noticed this behavior isn’t unique to my blog.

    To duplicate, go to any wp blog and add ?page_id=23423432434 to the end of the url, like this:

    If you try this on blogs listed in the Your WordPress forum, for example, you will get a blank page. That’s what I was getting before I added the <h2>Not found</h2> bit shown in my previous post.

    I’ll just wait for the search engines to catch up and stick with the “Not found” message. the 404.php file is useless. delete it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to generate 301 error for moved page?’ is closed to new replies.