Redirecting from Blogger to WordPress

I recently migrated my Dad's blog from Blogger to WordPress.

To transfer the content, I used Andy Skelton's import tool, which seems to have worked perfectly, especially when combined with Catstutorials' illustrated guide. Many thanks to both of these.

I managed to find a way to get Blogger to redirect to the correct post on the new WordPress site. Here is how I did it.

First, I made a backup of the Blogger template.

Second, replace the Blogger template with this (you'll need to change this to match your domain):

<html>
<Blogger>
<MainOrArchivePage>
<script language="javascript">
    var blog_root="http://www.yourdomain.com/blog/";
    document.location.href=blog_root;
</script>
</MainOrArchivePage>
<ItemPage>
<script language="javascript">
    var process_page="http://www.yourdomain.com/from_blogger.php";
    var newpage=process_page;
    var oldlink="<$BlogItemPermalinkUrl$>";
    newpage+="?p="+oldlink;
    newpage=newpage.toLowerCase();
    document.location.href=newpage;
</script>
</ItemPage>
</Blogger>
</html>

And then put the following PHP file into www.yourdomain.com/from_blogger.php:

require($_SERVER['DOCUMENT_ROOT'].'/blog/wp-blog-header.php');
$title = $_GET['p'];
$vars = explode('/', $title);
$num = count($vars) – 1;
$filename = $vars[$num];
$slug = str_replace(".html", "", $filename);
$SQL = "SELECT posts.* FROM $wpdb->posts AS posts WHERE posts.post_name = '$slug' LIMIT 1";
$posts = $wpdb->get_results("$SQL"); if ($posts)
    { foreach ($posts as $post) {
        $found_link = = get_permalink($post->ID); }
    } else {
        $found_link = "http://www.yourdomain.com/blog/";
    }
header("Location: $found_link");

It works for me …

Update: thanks to Tom Sherman for correcting my typo. 

12 thoughts on “Redirecting from Blogger to WordPress”

  1. hey
    Any chance you could but a few comments in this code. I would just like to get a bit of an overview as to what it is doing and my PHP and javascript knowledge are nonexistant. It would be particularly good to spell out what the main variables and functions do.

    Thanks

    rob

  2. Pingback: myBlog » Migrating from Blogger to Wordpress

  3. Pingback: jotsheet

  4. Thanks for this.. I found it quite useful.  However, there is a vital typo!  You conflate the variables "$title" and "$search_link". I’ve written up a tutorial for moving from Blogger to WordPress and included a much easier to read and typo-fixed version of this script.  Might want to give that a shot. 

  5. Pingback: deploy blog+ » Blog Archive » Migrer son blog de blogger / blogspot vers wordpress the seo blog

  6. Pingback: The Obscurer › Barbarism Begins At Home

  7. Pingback: 301 Permanent Redirect from Blogger Beta to WordPress | TechCounter - TechNews, Money & SEO

  8. Pingback: How To Redirect Traffic From Blogspot to Migrated Wordpress Blog | Zemalf

  9. Pingback: Wordpress Tutorial » How to Move all Post from Blogger to Wordpress

  10. can I scream now!
    my main page to blogger is redirecting. but all the subpages are not.

    my main website site is http://www.rebeccagrantham.com
    my blog is a subdomain
    http://blog.rebeccagrantham.com

    I am trying to redirect from my blogspot blog http://pleinairlandscapes.blogspot.com

    I am wondering if I should remove the entire template html code? and replace it

    or if I shoould try again and am just placing the php file in the wrong location.
    Given the info, where should I place the php file? direct path?

    Thank you
    Rebecca

  11. Pingback: How to move from Google Hosting to a Wordpress Hosted Site

Leave a Reply

Your email address will not be published. Required fields are marked *