WordPress.org

Ready to get started?Download WordPress

Forums

Redirecting post from blogger (1 post)

  1. newsinside
    Member
    Posted 7 years ago #

    Hi, I used to use a blogger.com account for my blogger, but I just installed a WP blog and its great! But since I used blogger for a long time, I already got many posts indexed in google. So, I would like to redirect all the users from google to my new posts. OK, I already created a "from_blogger.php" file, and it worked great in my test WP install, but when I transfer the DNS, the user will see the 404 eror page, not the from_blogger.php page I made.

    Anyway, I tought about this solution: Add the from_blogger.php code in the 404 WP page.
    the from_blogger page works in the following way:
    http://www.testWPinstall.com/from_blogger.php?v=www.URLFROMGOOGLE.com/tags/posts/post.html

    So, here are my questions:
    1. When the user visit the 404 page, how do I get the URL that brought it to the 404 page?

    2. Where should I place the code in the 404 page?

    3. which is the 404 page from WordPress? :P

    here is the code from the "from_blogger.php" page:

    <?php
    
    require('wp-blog-header.php');
    $search_link = $_GET['p'];
    $vars = explode('/', $search_link);
    $num = count($vars) - 1;
    $filename = $vars[$num];
    $slug = str_replace(".html", "", $filename);
    
    $SQL = "SELECT * FROM wp_posts WHERE post_name LIKE '$slug%' LIMIT 1";
    $posts = $wpdb->get_results($SQL);
    
    if ($posts) {
    	foreach ($posts as $post) {
    		$found_link = get_permalink($post->ID);
    	}
    }
    else
    {
    		$found_link = "http://trancemirror.com/wordpress/";
    }
    
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: $found_link" ); 
    
    ?>

    btw, im willing to change the "ELSE" part with the original 404 error code.

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic