As promised in my previous post (301 Meta Refresh Redirects: How Google and Yahoo Sees It), I will show you a script I wrote that will handle 301 redirects from Blogger to Wordpress using the meta refresh tag and javascript.
I have tested it on my old blogger (http://dannynsl.blogspot.com) and it seems to have worked fine so far.
There are a few steps you will first need to do.
- Install Wordpress on your domain. There should be installation tutorials on the website. I haven’t had time yet to do my own installation tutorial.
- Import your Blogger posts into Wordpress. In your dashboard, go to Manage and then Import.

- Change your permalink structure. In your dashboard, go to Settings and then Permalinks. The Day and name or Month and name settings should work. However, for my script I think Month and name should be safer.

- Use my javascript code just after the start of the <head> tag in your Blogger layout template. Note: Please make sure you do a backup before making changes. The variables that you need to change are old_root_domain and new_root_domain. This script handles redirection of individual posts, monthly archives and yearly archives. Anything else it will redirect to your homepage.
<script type='text/javascript'> /* * Written by Danny Ng (http://www.dannytalk.com/2008/07/25/how-to-301-redirect-from-blogger-to-wordpress/) * Free to use and distribute but must keep this comment in place. */ var post_regex = /^http:\/\/(www.)?.*\.blogspot\.com\/\d{4}\/\d{2}\//; var month_archive_regex = /http:\/\/(www.)?.*\.blogspot\.com\/\d{4}_\d{2}_\d{2}_archive.html/; var year_archive_regex = /updated-min=\d{4}/; var label_regex = /search\/label\/.+/; var old_root_domain = 'http://dannynsl.blogspot.com', new_root_domain = 'http://www.dannytalk.com', tag_url = '/tag/', redirect_suffix; if (post_regex.test(location.href)) redirect_suffix = (location.href.search(/www/i) == 7) ? location.href.substring(old_root_domain.length+4, location.href.length-5) : location.href.substring(old_root_domain.length, location.href.length-5); // -5 to strip .html else if (month_archive_regex.test(location.href)) { redirect_suffix = (location.href.search(/www/i) == 7) ? location.href.substring(old_root_domain.length+4, location.href.length-16) : location.href.substring(old_root_domain.length, location.href.length-16); // -16 to strip _XX_archive.html redirect_suffix = redirect_suffix.replace(/_/g, '/'); } else if (year_archive_regex.test(location.href)) { redirect_suffix = year_archive_regex.exec(location.href).toString(); redirect_suffix = redirect_suffix.replace(/updated-min=/, '/'); } else if (label_regex.test(location.href)) { redirect_suffix = label_regex.exec(location.href).toString(); redirect_suffix = tag_url + redirect_suffix.split('/')[2]; } else redirect_suffix = ''; document.write("<meta content='0;" + new_root_domain + redirect_suffix + "' http-equiv='refresh'/>"); </script>
If you want to do a 302 redirect equivalent, just change the number in the meta content from 0 to 1 or 2.
Hope this works for you and please let me know if there are any bug issues.
[edit date=26/07/08]
I just fixed the code to accommodate blog addresses with ‘www’ subdomains. As for redirects for labels, I’ll try to update the code for it tomorrow if I have time.
[/edit]
[edit date=27/07/08]
I’ve added a new regular expression to handle labels and also another variable tag_url that points to your permalink structure for tags or categories.
This setting can be found under Setting, then Permalinks and just scroll right down to the bottom. You will need to edit the variable tag_url to what you’ve sent in the permalinks structure. Make sure you add the ‘/’ at the end of it.
I think by default, Wordpress automatically imports posts from Blogger and sets the labels to categories instead of tags. In this case, just set the variable to the category slug name unless you can be bothered to go through all the posts and set them as tags instead.
[/edit]























August 15th, 2008 at 8:57 am
I think your code is exactly what I’m looking for, however I’m curious if it will work for my somewhat unique situation. My blogger blog uses a custom domain (www.eatingoutloud.com). The wordpress account is self-hosted using Yahoo (I know, they suck) and due to not having htaccess on Yahoo, my new wordpress URL structure must contain a reference to ‘index.php’ in order to create semi-decent permalink.
So, my old to new URLs will look something like this:
Old: http://www.eatingoutloud.com/2008/08/permalinkname
New: http://eatingoutloud.com/index.php/2008/08/permalinkname
In your code, is it as easy as making old_root_domain=http://www.eatingoutloud.com/ and new_root_domain=http://eatingoutloud.com/index.php ?
I appreciate any advice you can offer.
August 16th, 2008 at 1:14 am
Yes I’d say that would be fine changing the variable value old_root_domain to http://www.eatingoutloud.com and new_root_domain to http://eatingoutloud.com/index.php.
Make sure there’s no forward slash ‘/’ at the end of the string.
Give it a go and let me know if there’s any problems.
August 21st, 2008 at 4:35 am
What if I don’t want my new wordpress account to use the full name date path? I personally would like to leave the date out of the url… will it still work if I use name only?
August 21st, 2008 at 12:54 pm
Hi Charles,
Could you please give me an example?
October 12th, 2008 at 4:51 am
Hi Danny, suggestions how I can implement Blogger 301 redirects for pages but not for the root?
Like Allen above, I’ve been using a custom domain under Blogger and now self-hosting via Wordpress.org. So the domain is the same… but the Blogger pages end in html and the Wordpress pages don’t.
A few minutes ago, I tried a similar script at
http://www.libertyinteractivemarketing.com/blog/successfully-forwarding-blogger-to-wordpress/
I’m unsure between that and yours which is more reliable from a search engine perspective.
Suggestions? How to redirect the individual blog pages without being penalized for duplicate content? For the time being, I deactivated the custom domain in Blogger to be .blogspot.com; and set up a meta robots tag in Blogger to noindex and nofollow.
Any help would be appreciated. Thanks!
October 12th, 2008 at 5:02 pm
Hi Ari,
My script handles the .html extension so that shouldn’t be a problem. If you want don’t want to redirect your home page, then you can change the last ‘else’ state to something like
# .
# .
# .
# else
# ignore = true;
#
# if (!ignore) document.write(”<meta content=’0;” + new_root_domain + redirect_suffix + “‘ http-equiv=’refresh’/>”);
This will not redirect your homepage if the ignore flag will be set to true.
From a SEO perspective, neither both our solutions are the best because search engine crawlers aren’t able to execute javascript and thus, won’t be able to see the redirection although using the meta refresh is better SEO wise than document.location as crawlers can follow meta refreshes and not document.location.
However, the problem with using meta refresh to custom redirect pages for search engine crawlers is not doable because you would need to change the content value dynamically and you have to do it client side which once again, crawlers can’t understand. If you can do it server side, you wouldn’t even bother using meta refresh.
Also if you use something generic like <meta content=’0;http://somewebsite.com’ http-equiv=’refresh’/> all over your page, most likely you’ll get penalised as the destination content might be completely different to the source content and will be seen as irrelevant and perhaps “spammy”.
And yes, if you want to avoid duplicate content issue, just use noindex in the meta tags.
I don’t think there’s actually a very good way SEO wise to do 301/302 redirects client side but this solutions lets you drive traffic from your old site to your new one as your old website has a history with search engines and would probably rank higher for search terms. Best practice for redirects is to do it from the web server.
October 16th, 2008 at 6:56 am
Danny, this is a great script. Great? No way, It’s brilliant.I’m going to be writing a post about it tomorrow.
I’ve been scouring the web for months looking for something like this… Now, just one clarification.
is what you’ve said, but i’m not sure what this means… Does it mean that this script does not ‘really’ tell the Search Engine that the website has “permanently been redirected?” but just redirects the viewer?
Would like your clarification on that point.
Once again, “WOW” script. :D
Cheers!
October 16th, 2008 at 9:02 am
Thanks Susheel.
To explain what I meant in my previous comment, search engine crawlers cannot understand Javascript and thus, cannot execute Javascript. If you want to do redirects client side, you will need to use Javascript.
Most scripts will do the redirects dynamically based on the document.location value, and this isn’t known until the document object is ready. I have tried using an empty meta placeholder (<meta http-equiv=”refresh” content=”" />) without Javascript and then tried to insert the content value dynamically, but the refresh won’t work because the meta refresh executes as soon as it is rendered and because it has no value initially, it won’t redirect.
Setting the content value dynamically later on does not invoke the redirect. You have to somehow set the content value before the browser executes the meta refresh, and that is only possible with Javascript. Therefore, search engine crawlers won’t follow the redirect. Best practice is to do it with the web server and I wish people best of luck contacting Blogger for permission to do so :)
So what’s the point then of scripts like this? Well, since your old Blogger website has been indexed by Google and probably has some decent rankings on it, you want to capture the traffic driven to your old website to your new website. By doing so, people won’t be going to your old barren website now that doesn’t get updated but your new website, and all your good blog posts is still there! Your readers will be happy :)
I hope that explains it a bit clearer.
October 17th, 2008 at 12:55 am
Hi Danny,
Thanks a tonne for your explanation. It makes things very clear regarding the performance of your script. I’m just wondering whether you can put some note regarding this in your main article. I’m sure many people will miss it in the comments.
However, that does not clarify the title… is not a 301 redirect one that comes into effect globally? or is this just called a “client side 301 redirect”?
Once again, thanks for your time and patience in clarifying my doubts
October 17th, 2008 at 8:47 am
Yeah, I’ll probably put the explanation up in another post when I get time.
The title is aimed at people wanting to perform a redirect migration from their old blogger site to their new wordpress site. Most people would already know that this can only be done client side as you have limited access to Blogger’s backend. Even if you didn’t not know, this solution would’ve made it obvious that it uses client side scripting.
So yes, 301 redirect from blogger to wordpress would be assumed client side because it can’t be anything else :)
October 28th, 2008 at 9:05 pm
[...] danny: Yeah, I’ll probably put the expla… [...]
November 16th, 2008 at 2:33 pm
Danny, thank you so much for this!