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="">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>
Posted by holly0817 on February 25, 2011 at 8:04 pm
This worked great, thank you so much!!!
Posted by Violet Danson on February 27, 2011 at 2:15 am
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!
Posted by Etai on February 27, 2011 at 8:10 am
Thanks, guys! Happy to help.
Posted by Diana on March 4, 2011 at 11:13 pm
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!
Posted by madfishgrill on March 12, 2011 at 10:08 pm
Thanks… found this from the laffers post.
Posted by Katie Hetrick on March 21, 2011 at 7:47 pm
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!
Posted by Etai on March 21, 2011 at 10:43 pm
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.
Posted by Redirecting blogger post to wordpress.com | samueladesoga on April 26, 2011 at 5:16 pm
[...] inspiration from this post, I decided to write my own piece of javascript to make sure that each post is redirected to its [...]
Posted by bloggerclarissa on May 21, 2011 at 8:23 am
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!
Posted by Etai on May 22, 2011 at 11:46 am
It’s always great to hear that a piece of code you published actually helped someone !
Thanks for commenting.
Posted by Code That Redirects Visitors From Blogger to WordPress « Clarissa's Blog on May 21, 2011 at 8:29 am
[...] I just tried it and it works. This magical code can be found here. [...]
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.
Posted by Etai on June 8, 2011 at 8:49 pm
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.
Posted by chefivan on July 15, 2011 at 3:57 pm
Lovely! Works perfectly!
Posted by jonnyflash on July 28, 2011 at 2:16 am
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/
Posted by che on August 9, 2011 at 5:53 pm
thanks 4 fast loading the pilipino tele serye, i love it
Posted by The Diner of Cville... on December 1, 2011 at 3:20 am
Many blessings on your house! This was so easy! *applause*