Here’s a useful bit of Javascript that will redirect your old Blogger blog account to your new, self hosted WordPress blog account once you’ve imported all your old blogs.
It uses the search function in your new account to list the possible matches (usually just the correct one!). It works this way because the blog names on blogger are rarely the same as in wordpress, but it encourages people to update their links by showing them it’s different. It also displays a helpful message.
First go to your blogger account, select “Design” tab and “Edit HTML”. To get javascript in there, you’ll need to turn on “Expand Widget Templates”, and make sure any code is properly escaped, like the example below.
Now copy this piece of code, as is (except for line numbers), just after the Body tag:
- <h1>Blog has moved, searching new <a href='YOURBLOG'>blog</a>...</h1>
- <script type='text/javascript'>
- var splits = location.href.split("/");
- var splits2 = splits[splits.length-1].split(".");
- var search = splits2[0].replace( /-/g, "+" );
- window.location = "YOURBLOG/?s=" + search;
- </script>
Now replace YOURBLOG with the address to your blog (e.g. http://blog.akademy.co.uk )
Test it by going to one of your old Blogger blogs.
A helpful page at http://www.blogcrowds.com/resources/parse_html.php
Here’s a bonus one for WordPress to WordPress auto redirection.
Just change the old blog location to the new blog location. I’ve added a delay so anyone can see that it is redirecting and a message if the redirect doesn’t work.
Just paste everything from the next line into your header.php file just after the body tag. Then update the OLDADDRESS and NEWADDRESS bits.
<h1>Blog has moved, switching to new one automagically (please update you link!)…</h1>
<script type=”text/javascript”>
setTimeout(“switchToNewBlog()”,3000);
setTimeout(“alert(‘Switch over did not work. Goto: NEWADDRESS’)”,5000);
function switchToNewBlog()
{
var newLocation = location.href.replace(“OLDADDRESS”,”NEWADDRESS”);
window.location = newLocation;
}
</script>
Actually, this wordpress – wordpress relocation script is mich better:
Just put these lines at the very top of your header.php file and everything will automatically be redirected. Rankings on search engines should also redirect correctly with this:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.akademy.co.uk" . str_replace( "blog-tips", "blog", $_SERVER['REQUEST_URI'] ) );
?>
Use the str_replace function to switch from one website to another. e.g.: if you are moving from”www.oldblog.com” to “www.new.com/blog” use str_replace( “oldblog.com”, “new.com/blog”, $_SERVER[‘REQUEST_URI’] );
Since this code will automatically redirect the blog to another, is there any code for redirecting the blog if only the homepage is open? cos from Google or Yahoo, i searched my own post (for testing), then it only show the specific html (post title) for a while before redirected to a new link. What I want is only the homepage is redirected. not the post in the blog. Help me!~
Hi Nadia.
You’ll need to check whether you are on the homepage and then redirect if you are something like:
Note that some home pages can have several slightly different address such as : “http://blog.akademy.co.uk” and “http://blog.akademy.co.uk/index.php” – you’ll need to check for each one, just or them together:
Hope that helps.
Thanks so much for your code! This has been the only option that has worked for me that actually links to my direct post thus saving all my Pinterest, ect. exposure and links that are currently out there! I’ve tried like 5 other tutorials that didn’t work on my site. THANK YOU! 🙂
You’re welcome! 🙂
PS Love the Wentworth! 😉
Thank you SO MUCH! Works perfect. One of my clients had a blogger, which we redesigned and migrated to WordPress a few months ago… but no matter what messages and links we put on the old one, it just keeps eating all the traffic, and of course we are being penalized by Google because of the duplicated contents. We have configured the old blogger to not get indexed by search engines. I hope that helps with the second issue. Thanks again!
Hi, my old blog doesn’t seem to have a header.php in the code?
Where do i post this? I desperately need to get this working asap.
Many thanks.
Hi Dom,
You have to ensure the code gets added to all your blog pages. The header.php file is dependent on the template you are using, some templates may go against the recommended pattern.
Just make sure you add the code after the
tag whichever file that may be included in.Hey Matthew,
So I’m super new to this and I was wondering if you could tell me where to post this code. Which “tag” are you talking about?
my old blog is: http://musingsoftheliftedlorax.blogspot.com/
and the new one is:
http://musingsoftheliftedlorax.wordpress.com/
Perhaps you could provide the exact code I need and the place to put it?
I’ve been trying to migrate blogger to wordpress in hopes of salvaging my traffic and google cred, as my blog has become increasingly popular in the past months.
I am heaps appreciative of this thread because it’s the closest I’ve gotten…but still so far away. Look forward to hearing back.
Cheers!
Spence
I’m also getting an error that says:
“Could not load template preview: Error parsing XML, line 6, column 3: The processing instruction must begin with the name of the target.”
so I’m lost 🙁
This is perfect, I’m glad I found this page from a WordPress help page.
I moved from Blogger to WordPress approx. 3 months ago and even though I had Google stop indexing the Blogger site, I was still getting some traffic from older posts on blogs when I used my blogspot.com URL. Until now, I had a meta direct set but that’s not helpful as it only redirects to the homepage of the new site. This is perfect and working great, thank you.
One question though [since you’ve obviously been there and done that], in Google Webmaster Tools it is still reporting crawl errors from the correct website but from Bloggers permalink structure. I did have Blogger on my current URL before changing to self-hosted wordpress which is why the errors are reporting the correct URLs but wrong permalinks resulting in 404 errors. For example, it’s reporting http://www.sweet2eatbaking.com/2012/05/guest-post-rocky-road-bars.html is the incorrect URL (which it is) but not redirecting to http://www.sweet2eatbaking.com/guest-post-rocky-road-bars/ (correct URL). It shows where they’re linked from and I’ve fixed up most of the links which I can access. Is there anyway I can set a redirect so they go to the correct URL? My friend recently made the switch and her old URLs are being directed to the correct URL. How can I do the same?
Also, in Google Webmaster Tools, I rebuilt the XML sitemap so all the correct URLs are in place and resubmitted that but the above problems are still reported. If I search my site in Google, it looks like they’ve indexed the right permalink structure. I’m at a loss what to do.
Sorry this is so long. Hope you can help. Thanks in advance.
Hi Lisa,
Great looking site.
I’m no expert on this area unfortunately. As far as I know, google crawlers won’t follow the javascript redirect so maybe you should also add a meta redirect which they will understand. Maybe this wordpress plugin would be useful there: redirection.
Alternatively you could switch the Permalink Settings of your wordpress installation to match those which blogger used (i.e. with the year and month) – though that may cause errors on your current set up.
Sorry I can’t be more help.
Worded like a champ! Thank you so much for making my life easier and my client happy.
I did remove the, + search; just bc it wasn’t pushing it to the homepage, but otherwise… BRAVO!
WOW! This is a great post. I have been looking for a way to make this happen and your post has made it seem very easy. Will try it out soon. Thanks for sharing.
Hi, i have followed ur instruction to redirect blogger to wordpress and it work very well. But it got redirected to my blogpost in the new website instead. I hope to redirect it to the home page actually. I saw a similar post on your forum but i think its slightly different because I’m redirecting it from blogpost to homepage, not homepage to homepage.
my old blog is: http://marcusfitness.blogspot.com
my new website is: http://marcustamfitness.wordpress.com
Please help me as I already cracking my brain over it. Thank u so much!
its ok. i found the solution. Using your HTML codes, i simply removed some parts towards the end. i removed ?s=, and also removed +search;,
i had no knowledge of HTML codes and i am damn lucky to figure it out.
But anyways v v v much for your redirection codes! Really appreciate your good work! Cheers!
Worked wonderfully! Thanks a million!
Thanks, the code worked perfectly except of one big problem. The url of the old site (http://cononsense.blogspot.co.il/) posts is based on their publish date, and the url of the new site posts (http://mottyf.wordpress.com/) is based on their title, so the search operation doesn’t work. Do you have an advice for me?
Thank you very much
I’m afraid this code wont be able to help as it only works off the URL.
You’ll have to get the title in javascript then append that to the new search url instead of splitting the existing url.
This was a life saver! Thank you!