Blogger WordPress Import Anyone Can Do

This free Blogger WordPress Import -guide is for anyone who has a blog in blogspot and want to migrate the blog to self-hosted WordPress.org based blog (which is, the best way to host, write and maintain a blog).

Similar methods can be used to import and redirect traffic from any blog or website of yours, but I only have first-hand experience with the blogspot, import from there and redirect the traffic from blogspot to the new domain / blog.

With the redirect method presented on this article, you can use any kind of permalink structure in WordPress

In this article, I will show you how I

  • transferred my two blogspot blogs to one wordpress blog and kept all the traffic and links from the old blog
  • used WordPress custom fields to find the migrated posts, with any kind of permalink structure

Background

I wanted to migrate two of my *.blogspot.com blogs to this new WordPress based blog with these requirements:

  • import and migrate the blogspot blogs to this one WordPress blog
  • 301 redirect all traffic from the old blogs to the new blog. Unfortunately "true" 301 redirect is not possible without server level access (namely .htaccess file), so we go for the second best thing.
  • if possible, redirect to the corresponding blog post on the new blog, in case permalink was used for the old blog
  • redirects should work, even if I edit the posts in the new blog, and/or change the permalink structure

Starting the WordPress blog, installing plugins, setting things up before importing and then the Importing Blogger Content were all quite simple tasks. Here are some great guides to checklist all the basic setup tasks and get you started with WordPress blogging:

Use Any Permalink Structure on WordPress

But redirection was bit trickier, but relatively simple once it's done.

This redirection solution will handle redirect from old blog post to the same imported post in the new blog succesfully, even if WordPress permalink structure would be changed, because the Custom Fields in the posts will remain.

Which means that it is not necessary to use the "blogger-like" permalink structure with the .html in the link - Redirection will work with any permalink structure.

In most of the other guides, so must use permalink structure like this when you begin import/redirect from blogger/blogspot:

/%year%/%monthnum%/%postname%.html

but using the Custom Field redirect, your permalink structure can be anything, in fact you don't even have to have permalinks enabled for this redirect to work!

Of course, you should have permalinks enabled and you should have postname in the permalink, as it makes the URL understandable and it's more SEO-friendly.

The best permalink structure depends on your blog, but in short your choice should come from:

  • /%postname%/
  • /%post_id%/%postname%/
  • /%category%/%postname%/
  • /%year%/%month%/%day%/%postname%/

The magic behind this is the Custom Fields, created automatically by the WordPress Import to all the imported posts from Blogger.

We only have to extract the permalink path from Blogger and pass it to .php script on the new domain which queries the SQL database for the correct post, based on the Custom Field meta data.

This was done using the WordPress version 2.7.1. - but always use the latest version of WordPress to avoid problems.

Redirect Traffic From Blogspot WordPress Blog

Warning! I imported and redirected my own blogspot blogs using these scripts. This does not guarantee that you won't have any problems. I've been messing around with computers and programming for over 20 years, and it took me a while to figure this out. Thus, proceed with caution, and come back here and leave comments if you have problems.

The redirection like this works for other imported blogs as well, in case you have access to the html-template of the old blog and similar "blogger_permalink" custom field is generated during the import from other blog platforms.

STEP 1 - Blogspot Template (redirection to the new blog)

  • Go to the blogspot blog settings, and edit the html. Switch to Classic Template.
  • Add these lines to the blogspot template after <BLOGGER> tag:

<MainOrArchivePage>
<script language="javascript"><!--
var blog_root="http://YOURNEWDOMAIN.com/";
document.location.href=blog_root;
//--></script>
</MainOrArchivePage>
<ItemPage>
<script language="javascript"><!--
var process_page="http://YOURNEWDOMAIN.com/bloggerposts.php";
var newpage=process_page;
var oldlink="<$BlogItemPermalinkUrl$>";
newpage+="?p="+oldlink;
newpage=newpage.toLowerCase();
document.location.href=newpage;
//--></script>
</ItemPage>

  • Add these lines between the <HEAD> and </head> tags, to manage those with javascript disabled:

<meta name="robots" content="noindex, follow"/>
<meta name="googlebot" content="noindex, follow"/>
<noscript>
<meta http-equiv="refresh" content="0;url=http://YOURNEWDOMAIN.com/" />
<meta name="description" content="301 moved permanently"/>
</noscript>

  • Remember to replace YOURDOMAIN.com with yours (e.g. example.com).
  • (optional) The refresh and javascript should handle almost all users, but just in case someone is left standing on the old blog, find <BlogItemTitle> tag from the blogger/blogspot template, and replace it with this (again replacing YOURNEWDOMAIN.com with your domain name, e.g. example.com):

<BlogItemTitle>
<h2>Blog Has Moved</h2>
<p>Link to the same post in the new blog: <a href="http://YOURNEWDOMAIN.com/bloggerposts.php?p=<$BlogItemPermalinkUrl$>"><$BlogItemTitle$></a> </p>

STEP 2 - Finding the correct post on the new blog

  • Download the bloggerposts.php (zipped)
  • Unzip, edit the file with your domain info, and save the edited bloggerposts.php to your blog's root (where your index.php is)
  • or create a text file, and save it as "bloggerposts.php" in your blog's root with this text (there's "copy to clipboard" button on the top right corner of the source code displayed with a plugin):

<?php
require($_SERVER['DOCUMENT_ROOT'].'/blog/wp-blog-header.php');
$search_link = $_GET['p'];
$old_permalink_path = str_replace("http://YOURBLOGSPOTNAME.blogspot.com", "", $search_link);
$sqlquerystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'blogger_permalink'
AND wpostmeta.meta_value = '$old_permalink_path'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
LIMIT 1
";
$posts = $wpdb->get_results("$sqlquerystr");
if ($posts) {
foreach ($posts as $post) {
$found_link = get_permalink($post->ID);
}
}
else
{
$found_link = "http://YOURNEWDOMAIN.com/";
}
?>
<html>
<head>
<title>Redirecting you to the post you are looking for</title>
<script language="javascript"><!--
document.location.href="<?php echo ($found_link); ?>";
//--></script>
<meta http-equiv="refresh" content="2;url=<?php echo ($found_link); ?>">
</head>
<body>
<h1>Redirecting you to the post you are looking for...</h1>
<p>You can also proceed immediately to <a href="<?php echo ($found_link); ?>"><?php echo ($found_link); ?></a>.</p>
<p>The main blog URL is <a href="http://YOURNEWDOMAIN.com/">YOURNEWDOMAIN.com/</a>.</p>
</body>
</html>

  • Remember to edit your domain there (e.g. example.com) in there instead of YOURNEWDOMAIN.com
  • If you are using Google Analytics (like you should), add the analytics code just before the </body> tag.
  • I have WordPress installed in separate directory, so remove the /blog from the first line, if you have wordpress installed in your domain root.

require($_SERVER['DOCUMENT_ROOT'].'/blog/wp-blog-header.php');

  • if you don't have wordpress in separate directory (blog) replace the above with this:

require($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php');

  • or edit in your directory / path to the line:

require($_SERVER['DOCUMENT_ROOT'].'/YOURDIRECTORYHERE/wp-blog-header.php');

  • Replace my old blogspot blognames with your *.blogspot.com:

$tmp_link = str_replace("http://YOURBLOGSPOTNAME2.blogspot.com", "", $search_link);
$old_permalink_path = str_replace("http://YOURBLOGSPOTNAME.blogspot.com", "", $tmp_link);

  • If you only have one blogspot blog you are transferring to wordpress, replace this line....

$old_permalink_path = str_replace("http://YOURBLOGSPOTNAME.blogspot.com", "", $search_link);

  • with this one:

$tmp_link = str_replace("http://YOURBLOGSPOTBLOG2.blogspot.com", "", $search_link);
$old_permalink_path = str_replace("http://YOURBLOGSPOTBLOG.blogspot.com", "", $tmp_link);

STEP 2.5 - Update your feedburner feeds

(optional) If you have had your blogspot feeds at feedburner (which I highly recommend), you have two options:

  • Use new feed: Create a new feedburner feed for your new blog

or

  • Use your old feed: Edit your old feed and change the feed address to the new blog:
  • Login to FeedBurner, go into the feed and click on “Edit Feed Details.” Change your feed address to http://YOURNEWDOMAIN.com/feed/

STEP 3 - Enjoy the results.

  • DO NOT DELETE YOUR OLD BLOGGER / BLOGSPOT BLOG!
  • See all the old readers find the new blog automatically and
  • Old links being redirected to the new blog.

That's it, now start adding some new content with the shiny blogging platform on your own domain!

Blogger WordPress Redirection Summary

Redirecting traffic from old blogspot blog to a new WordPress blog

  1. EDIT the blogspot template (switch to classic!!)
  2. INSERT the javascript code and the meta http-equiv refresher as instructed
  3. SAVE the bloggerposts.php in the blog root

Credits and related articles

I looked for scripts and guides from several blog posts, and took the best parts, added, corrected and improved the code and created the modified bloggerposts.php to enable redirection to any kind of permalink in the wordpress:

Afterword & Warning

After I enabled the redirection from blogspot blogs, I immediately received spamblog block from blogspot spiders/robots. This was lifted a day later after I asked for inspection.

So be warned, but don't worry: You will very likely get the spamblog block and "your blog will be deleted in 20 days" from blogspot, but this will be lifted as you request to reopen and inspection, as the redirect like this is ok.

Of course, we'd love to have 301 .htaccess redirection, but we can't have that with free blogging platforms (again, one more reason why self hosted blogs are better and safer for your blogging future).

p.s. If you have used this method and my script, PLEASE come back here and tell it in the comments. Just say "It works" if you like, but I'd love to hear from you. I even give you permission to leave your OLD blogspot link and NEW URL link to the comment (which is normally against my comment policy). Thanks!

Here's more posts like to this:
  1. Blogspot Blog Migration to WordPress
  2. Replacing “No comments” with “Leave a comment” in WordPress
  3. How to show number of comments in WordPress
Posted by

Topic: Blogging
Tags: , , , ,

If you enjoyed this post, sign up for updates (it's free)


Feedback, questions and comments are also welcome on my Facebook page