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. 

If you enjoyed this post, please consider leaving a comment below, and perhaps sharing this with other people using the buttons on the left. You can also sign up to have blog posts sent to you by email.

11 Responses to Redirecting from Blogger to WordPress

About Owen

Owen Barder is the Europe Director at the Center for Global Development. He writes here about development, economics, politics, computers, running, and anything else that interests him. He also hosts Development Drums.


Get posts by email
Recent Comments
Recent posts
Will Cameron persuade the G-8 to take on tax evasion?Tax, trade, transparency … & turf
April 23, 2013
1 comments

Jim KimFor the first time ever (World Bank edition)
April 19, 2013
4 comments

bannerThe Europe Development Digest
April 16, 2013
0 comments

manningAre rich countries ‘getting away with murder’ by massaging aid figures?
April 11, 2013
0 comments

The RulesGlobal wealth inequality
April 8, 2013
1 comments

Food recycling facilityWaste not, want not
April 1, 2013
0 comments