How To Redirect Traffic From Blogspot to Migrated WordPress Blog

This How To 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

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:

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. – in case of problems with earlier versions, reinstall/update your Wordpress and reimport.

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://zemalf.com/";
document.location.href=blog_root;
//--></script>
</MainOrArchivePage>
<ItemPage>
<script language="javascript"><!--
var process_page="http://zemalf.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://zemalf.com/" />
<meta name="description" content="301 moved permanently"/>
</noscript>

  • Remember to replace my URL (zemalf.com) with yours.
  • (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 zemalf.com with yourdomain.com):

<BlogItemTitle>
<h2>Blog Has Moved</h2>
<p>Link to the same post in the new blog: <a href=”http://zemalf.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'];
$tmp_link = str_replace("http://pokerwits.blogspot.com", "", $search_link);
$old_permalink_path = str_replace("http://zemalf.blogspot.com", "", $tmp_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://zemalf.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://zemalf.com/">zemalf.com/</a>.</p>
</body>
</html>

  • Remember to edit yourowndomain in there instead of zemalf.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://YOURBLOGSPOTNAME1.blogspot.com", "", $search_link);
$old_permalink_path = str_replace("http://YOURBLOGSPOTNAME2.blogspot.com", "", $tmp_link);

  • If you only have one blogspot blog you are transferring to wordpress, replace these two lines….

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

  • with this one:

$old_permalink_path = str_replace("http://YOURBLOGSPOTNAME.blogspot.com", "", $search_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://YOURNEWURL.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 best blogging platform :)

Summary – Redirecting traffic from old blogspot blog to a new Wordpress blog

  1. EDIT the blogspot template (classic)
  2. INSERT the javascript code and the meta http-equiv refresher as instructed
  3. SAVE the bloggerposts.php in your blog’s 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).

If you enjoyed this article, you might find these useful as well:

  1. Blogspot Blog Migration to WordPress
  2. Bulk Edit Posts, Categories and Tags on Your WordPress Blog
  3. WordPress Settings for Every Blog

Topic: Blogger WordPress Import
Tags: How-To, javascript, mysql, php, WordPress
| Antti Kokkonen | Comments

Comment policy: We're gonna be like little Fonzies here. And what's Fonzie like? Cool. Correctamundo, and that's how we roll here -- cool. Critical is OK, but if you're rude, spam or otherwise misuse the blog comments, I will delete your comment. Do not put your URL in the comment text. Please, use your PERSONAL name or initials. Do not use your business name, keywords or anything like that, as that comes off like spam. Have fun, be excellent to each other and thanks for adding to the conversation!

  • Hi Zemalf, great post!
    I am trying to get the redirection working, but the url, when redirected from Blogger, stays as
    http://www.universodemoda.com/2009/04/surf-in-c...
    ending with .html, and showing 404 error.
    What am I doing wrong?
    Thanks a lot!
  • Hey Carlos.

    Are you using the bloggerposts.php file that is in the zip file? And did you copy the blogger redirect to blogger template and just replace zemalf.com with your own?

    Seems that you are redirecting to:
    domain/blogger_permalink
    instead of:
    domain/bloggerposts.php?p=blogger_permalink

    ..check the redirection code on the Blogger side that it is exactly as in the post, and make sure the bloggerposts.php is set on the WP side.
    .-= Zemalf´s last blog ..Keyword Research Primer =-.
blog comments powered by Disqus