Redirecting visitors in an old Blogger blog to new location on wordpress.com

Blog Technical Scale: 5 (if you need it, you’ll do fine)

So,

As part of moving the blog to its new location, I was faced with a minor challenge – redirecting users from my old blogger blog to my new wordpress blog.

The task is pretty trivial if you happen to be a programmer – you just add a redirect code in your old blog headers. But I wanted a little more than that – I wanted people to be redirected correctly, so that if they were viewing a specific post, I’d redirect them to that same post on wordpress.

To make a long story short, I found a few posts on the web describing how to do that, but they were either old or were assuming you are hosting your own wordpress. Eventually, being who I am, I decided to crack it myself. I used an old post from laffer.net, that  and was no longer relevant, but provided big help in setting a direction.

Eventually I managed to do it, so I figured I’d share it here. There’s a good chance that this method will cease to work one day, just life the old method laffer.net had is no longer working. But until then perhaps someone will find it useful. Here’s what you do:

1) Go into your blogger’s admin area. Choose the “design” tab, “Page Elements” (where you see the different blocks that your page is made of).

2) Click on “add a gadget” anywhere and choose the html/javascript gadget.

3) In the screen the just opened, paste the code below in the “content” section, and leave “title” empty.

4) Replace the wordpress and blogger urls from my urls to yours (look for etairaz.wordpress.com and itairaz.blogspot.com).

That’s it. You now have a banner on top of your site that tells people they are about to get redirected in 5 secs, then redirects them.

This is *not* SEO friendly, but I couldn’t care less since I’m not one of those SEO crooks (subject for another post). It won’t work on a browser that doesn’t support Javascript, but again – who cares.

Enjoy!

</pre>
<div style="position: fixed; top: <span class='hiddenSpellError' pre=&quot;&quot;>30px</span>; left: 30px; border: solid 2px #333; color: #000; background-color: yellow; padding: 5px; width: 400px; z-index: 5; font-family: verdana, geneva, arial, helvetica, sans-serif; font-size: large;"></div>
<pre>
	<div><strong>My blog has moved!</strong></div></pre>
<div>You should be automatically redirected in 5 seconds. If not, visit
<a class="<span class=">redirectLink" href='http://etairaz.wordpress.com/'> <span class="redirectText" style="font-weight: bold; color: #bb0000;">http://etairaz.wordpress.com</span></a>
 and update your bookmarks.</div>
<pre>
</div>

<script language="javascript" type="text/javascript">
function addZero(numberToPad)
{
	return ("0" + numberToPad).slice (-2);
}

var m_wpUrl = 'http://etairaz.wordpress.com/';
var m_published = document.getElementsByClassName('published');
if(m_published.length == 1)
{
	m_published = m_published[0].getAttribute('title');
	var m_pubDate = new Date(m_published);
	var m_url = location.href;
	var m_lastSlash = m_url.lastIndexOf('/');
	var m_lastDot = m_url.lastIndexOf('.');
	var m_postName = m_url.substring(m_lastSlash + 1, m_lastDot);
	if(m_lastDot > 0 && m_postName.indexOf("_archive") < 0) m_wpUrl += m_pubDate.getFullYear() + '/' + addZero(m_pubDate.getMonth() + 1) + '/' + addZero(m_pubDate.getDate()) + '/' + m_postName;

}
//redirect in 5 seconds
window.setTimeout(function(){location.href = m_wpUrl}, 5);

//change text
document.getElementsByClassName('redirectLink')[0].setAttribute('href', m_wpUrl);
document.getElementsByClassName('redirectText')[0].innerText = m_wpUrl;

</script>

Advertisement

17 responses to this post.

  1. This worked great, thank you so much!!!

    Reply

  2. I love this so much!!! I have been looking for this code for a long time and finally there is something that works!!! Thanks you so much!

    Reply

  3. Thanks, guys! Happy to help.

    Reply

  4. This worked! Thank you so much! I have been struggling with this for a while since I have no experience with such things and I am only now learning. I was so happy to find your post!

    Reply

  5. Thanks… found this from the laffers post. :)

    Reply

  6. This is so easy! Thank you! I am just so glad there are people like you who take the time to post this information in an easy-to-follow way…especially for those of us who know just enough to be a danger to ourselves!

    ADVICE NEEDED:
    We went from blogger to a self-hosted WP site. I used your gadget and it is working great at redirects to the new blog, but not the specific post. (Everything goes to the most recent post page.) Does that make sense? Do you know why that may be or of any other easy to follow fixes?

    Thank you again!

    Reply

  7. Kate,
    The whole idea of creating this drill was to redirect people to the specific post on the new blog. If this is not working for you, then I guess the script is only half working.
    Perhaps there’s something to do with the fact that you’re self hosting, and I was targeting a wp.com hosted site. If you know a bit of Javascript, you should check to see what’s going wrong there. Essentially the code is supposed to grab the post name from blogger, and redirect the user to the same one on wp.

    Reply

  8. [...] inspiration from this post, I decided to write my own piece of javascript to make sure that each post is redirected to its [...]

    Reply

  9. Thank you, this is the only code out there that actually works and redirects individual posts to the same posts on WordPress. My gratitude knows no limits. I was terrified of losing my traffic after moving to WordPress and now I don’t have to worry any more.

    Thank you so much!

    Reply

  10. [...] I just tried it and it works. This magical code can be found here. [...]

    Reply

  11. Posted by Tom on June 8, 2011 at 11:44 am

    Hi, this works perfectly in Firefox but not in IE. Any ideas on how to get it working for all browsers?

    Thanks.

    Reply

    • Seems to be partially working in IE (redirects, but not to the right post). I probably won’t have time to check why this is – sorry about that.

      Reply

  12. Lovely! Works perfectly!

    Reply

  13. Thanks, this works great. Although for those who want a somewhat simplier way and you host yourself, there is this wordpress.org plugin:

    http://wordpress.org/extend/plugins/blogger-to-wordpress-redirection/

    Reply

  14. Posted by che on August 9, 2011 at 5:53 pm

    thanks 4 fast loading the pilipino tele serye, i love it

    Reply

  15. Many blessings on your house! This was so easy! *applause*

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.