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.
When assigning values to old_root_domain and new_root_domain, DO NOT use ‘/’ at the end.
<script type='text/javascript'> /* * Written by Danny Ng (https://www.dannyism.com/2008/07/26/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 = 'https://www.dannyism.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;URL=" + 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]
[edit date=14/02/08]
Just found a bug (thanks to Chris Lee) that the redirection didn’t seem to work in IE7. For some reason I needed to add URL= in the meta content attribute for the redirection to work.
Basically I just changed,
document.write(“<meta content=’0;” + new_root_domain + redirect_suffix + “‘ http-equiv=’refresh’/>”);
to
document.write(“<meta content=’0;URL=” + new_root_domain + redirect_suffix + “‘ http-equiv=’refresh’/>”);
Please let me know if you guys ever come across bugs for this script and I will try my best to fix it as soon as possible :)
Happy Valentines Day everyone!
[/edit]
very nice solution man! does this javascript redirect passes link juice?
No I don’t believe they do pass link juice as traditionally, search engine crawlers are unable to go crawl javascript links. However, this is probably changing over time as they get smarter.
dude pls give me solution..your 301 redirect code refresh my new domain pages also and redirects all pages to home page after few minutes.
pls help me…
If you can show me what you’ve done, I can take a look at it.
thanx dude for this code…
The code works. But is this SEO friendly so no traffic or pagerank will be lost??? Is there something else we can do to prevent loss of pagerank and traffic. I just did the chane on my site and I lost 75% of my traffic.
Jamie,
Best way to do this in a SEO friendly way is to do the redirects server-side. Unfortunately you do not have control over this through the Blogger’s interface. Hence, we are using javascript instead.
With regards to your loss in traffic, have you analyse what kind of traffic did you lose (i.e. direct, organic, referral)?
Permalink
Danny,
I’ve looked all over and yours is the simplest way to do this out of everything I’ve found. To make the redirect even faster, I went into blogger after installing your code and I took out all my widgets, sidebars, etc. and everything that needed to load so basically Blogger just loads the post only then redirects and it’s pretty quick. Old blog is http://thoughtleadersllc.blogspot.com and new blog is http://www.thoughtleadersllc.com/blog. This is a really nicely formed and effective script.
One question – what would I add to your script (and where) to get the main http://thoughtleadersllc.blogspot.com to redirect to http://www.thoughtleadersllc.com/blog instead of just redirecting to http://www.thoughtleadersllc.com? I know I would add an else in there somewhere but not sure how to properly form it and I don’t want to mess up the rest of your code which is working PERFECTLY.
You’re awesome. Thank you SO MUCH for this!
Hi Mike,
I haven’t tested this yet and it’s been like 3 years since I’ve looked at this code (!) but I believe you change the variable declaration part at the top,
new_root_domain = ‘http://www.thoughtleadersllc.com/blog’
Hope this works.
Wow! This is a big help. Thanks for posting this! :)
Permalink
This post is one of the best I’ve come across. Actually came across some another tutorial before this one which was a bit too nagging. It asked to upload a file into WordPress directory, add a code to blogger at two places and was a real hassle. This code is the ultimate one… that I had been looking for. Great post man.
I want to ask something. Is there a way to redirect to the new domain without any time lag? Like you know, is there a way for the redirect to happen seamlessly as done by .htaccess redirects?
Hey Danny, the blogger blog not hosted with godaddy just the domain name and they will not let me transfer it to my hosting company so I could transfer the blog on to wordpress using that domain name and do a 301.
The above code throws an html error on blogger.
Any ideas would be great.
Nice facelift on the blog.
By the way, I only have the refresh activated on the blogger html. Also I have a script in the body to redirect each post to the proper post on wordpress, but neither are 301 redirects. I still get a 200 ok on everything.
Thanks
Hey Danny I have a custom domain with blogger http://www.enlightentravels.com that is hosted with go daddy, but bought through blogger. I moved the blog to wordpress to http://travelenlightenment.net.
The script you have works great for a .blogspot but not for a custom domain. would you know how to change the code for it to work for a custom domain.
Ironically, the 301 forward on Go Daddy does not work. it is only for the naked domain and not the www. sub domain.
Although I was able to do an address change through google webmaster tools, buy inserting the meta tag.
Any help changing the code so the html header will read a 301 would be great,
Thanks
Hi Shawn,
If your old blog was hosted with GoDaddy, you would need to configure the server-side redirects on GoDaddy’s hosting interface.
If the URL structure is the same and the only difference is the root domain, you can probably do something like,
<script type=”text/javascript”>
var request_uri = document.location.toString().substring(document.location.toString().indexOf(‘.com’)+4, document.location.toString().length);
document.location = ‘http://www.travelenlightenment.net’ + request_uri;
</script>
Note the script above hasn’t been tested.
Unfortunately this script is meant to serve for the migration from Blogger (blogspot) to WordPress (custom or wp hosted).
Hi,
I can’t redirect. Can you help me plis, i do everything you say, but nothing happen. My blog is:
http://juegosdeface.blogspot.com
and i like redirect to
http://www.facebookjuegos.net
Regards
Hi Azahi,
You’ll need to give me more details as to why it isn’t working for you then I can look further into it.
Hey Danny!
Just wanted to say thanks for your script – really helped me and my beautiful client at eatdrinkplay.com – big props from down under.
Cheers,
Jye
Thanks for this script. Very helpful.
But I have a small problem, which I am sure you can solve.
I redirected http://www.xyz.blogspot.com to http://www.xyz.com
But the inner pages are not redirecting properly.
Ex:
If I have a page: http://www.xyz.blogspot.com/xyz.html then it gets redirected to http://www.xyz.com/xyz.html but I want it to redirect to http://www.xyz.com/xyz (I don’t want the .html extension in the redirected address). Can you please help.
Thanks
Hi Satish,
The script actually strips out the ‘.html’ portion. It’s meant to anyway. You would need to show me the example so I can see what’s causing the problem.
If you want to do a 302 redirect equivalent, just change the number in the meta content from 0 to 1 or 2.
Actually this number is a delay in seconds before it performs the refresh and not the type of redirect. I use this for a 5 second delay before redirecting.
Very well explained tutorial.
This is brilliant Danny. I’ve looked at many sites on how to redirect but they were all a bit too complicated. This is very straightforward and works an absolute treat!
Hi Danny!!
Congrats for your Great Script. I moved from Blogger to a new domain under wordpress and this works fine for me.
I was reading another solution inserting the following code in the blogger Html layout:
Although blogger avoids me to save it…I really was not sure if something was missing but I tried your script with success.
I only have a question, where your scripts says:
document.write(“”);
I wonder if this “0” value is for redirect 301? or should I change it to “1”?
From the SEO prespective, I will also see what happens…what I am going to do is inserting NoIndex, Nofollow meta right away to avoid getting penalized for duplicated content.
Thank you in advance again for your good script and explanation of it.
Best Regards from Spain
Jose
I think even if you put 0 or 1 there’s no difference as search engines don’t execute javascript. This is a client-side redirect.
In regards to duplicate content, there’s really no such thing as “penalty”. It’s something that have been afraid for too long without really understanding what the implications of duplicate content are. Search engines such as Google will scan the web and identify “duplicate content” on the web and algorithmically tries to attribute organic rankings to the original source.
There simply isn’t any “penalty” involved, just that if you’re a copy cat, you won’t be rewarded with it as opposed to the original content source.
It works! Thanks Danny. Been searching around to redirect Blogspot’s blog to other websites. :)
Permalink
Permalink
Thanks, Danny. My website is not that large, so it was definitely doable, but I wasn’t sure how to do it until I realized a plugin could do it easily. Works like a charm.
The script works for me. However, when I moved from blogger to wordpress, some of the permalinks changed and the redirect can’t locate the post at the new location. Other than changing the permalinks on the WP blog to match the blogger permalink, which I don’t want to do, is there a way of correcting the address redirect for specific posts? For example, redirecting http://www.example.blogspot.com/to-lighthouse.html to http://www.example.com/to-THE-lighthouse. Thanks –
I installed a redirection plugin (http://urbangiraffe.com/plugins/redirection), which seems to be fixing the problem. Your code sends the post from blogger to a nonexistent URL and the redirector sets it straight. Not sure if that the best way to do it, but it seems to be working for the ones I’ve tried.
The script assumes that you’ve done the standard import of posts from blogger to wordpress and that the URLs are the same (i.e. to-lighthouse.html -> to-lighthouse, not to-THE-lightouse).
Seems like what you’re trying to achieve is custom redirection mapping which I suppose you may be able to do with a wordpress plugin but will be a pain in the butt if you have a large website and you’re trying to custom redirect all of them.
Thank you so much for your code. I have been trying with different solutions and yours is the only one that is simple and work!!!!
I have little problem with my category link but it’s because I moved around my category when I migrate to wordpress so I use redirect plugin to fix those minor issues.
Great code and thank you for sharing!!!
Thank you soo much for this great pice of code! Works like a charm, and it was really easy to understand how to add it :D
Hello! Thanks for a great script. But I have a small problem. I use a custom domain that’s not blogspot.com but the blog is hosted at blogger. So I´ve changed where you have: 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/;
And erase the blogspot.com but then the redirect became like http://www.mysite.com09/04/permanentlink. There is missing 20 in 2009. Do you have any tip?
I’ll need to know what did you change it to (the regex).
Hi Gary,
Seems like if you’re hosting both of your website, you may be able to do this via your htaccess file (xxxx.com) if you’re using an Apache server.
Something like this may work (not tested),
RedirectMatch 301 /myblog/(.*) http://yyy.com/author/myname/$1
hey danny –
I’ve been trying to figure out how to get my blog to redirect. It should be an easier deal as my original blog was a blogger blog, but hosted on my own hosted account. and the new blog is on the hosted account.
Do have a tutorial of writing a 301 redirect in this case? An example of my blogger to wordpress set up would be:
xxxx.com/myblog/ to yyyy.com/author/myname/
Thanks for any thoughts you may have.
What I have to do to the new blog shows on google listings for the same content that i still have on the old one.
I know that i should had a self domain on blogger for a couple of weeks and then change hosting.
I hope that you understand.
I lived in melbourne for 3 years but my english is a bit rusty now.
Ah yes, I had to deal with that one as well when I migrated my blog to my own domain from Blogger.
This is quite simple. Basically you’ll need to go to your Blogger layout, and click on Edit HTML.
Within your <head> tags, place the following code,
<META CONTENT=’NOINDEX, NOFOLLOW’ NAME=’ROBOTS’/>
What this does is basically tell search engine robots to not index your pages and also not to follow the pages found on the pages. You can read more at the robots website. What you’ll notice over a period of time is that search engines such as Google will stop indexing your old website and remove it from the search engine results page.
You can use the site: operator to monitor how many pages are currently indexed by Google.
How can you make the re-direct quicker, Danny?
And the NO-INDEX tag cannot save on my blogspot
Hmm, unfortunately client-side redirects are limited in what you can control. Not entirely sure how to make the redirects quicker without forcing the browser to somehow stop loading the document.
Not sure why the noindex tag can’t save on yours. It saves on me. What’s the error message?
Hi danny,
What can i do to avoid duplicated content, should i change definitions to
Add your Blog to our listings-no
Thanks again for your help
Hi Paulo,
There are several ways to avoid duplicate content but before I proceed, can you please explain the current situation you’re experiencing? That way I may be able to provide you a solution specific to that.
Thanks Danny
It worked perfectly
Hello.
This script isn´t working for me when it comes to redirect a post,
meaning:
redirect this
http://dicas-sobre-alarmes-cobra.blogspot.com/2008/11/como-programar-um-comando-de-alarme.html
to:
http://alarmescobra.com/2008/11/como-programar-um-comando-de-alarme-cobra-novo/
I tried all the kind of permalinks and still not working
What i am doing wrong since looks like that is working for every one.
If you could help me.
By the way your email feed is not configurated.
You may lose subscribers,lol.
The email feed subscription has been fixed. You can subscribe now! :)
Hi Paulo,
Exclude the ‘/’ at the end when you’re assigning the variable old_root_domain.
So instead of
old_root_domain = ‘http://dicas-sobre-alarmes-cobra.blogspot.com/’
it should be
old_root_domain = ‘http://dicas-sobre-alarmes-cobra.blogspot.com’
I should’ve mention that in my post. Give that a go and let me know how it goes :)
Thanks for letting me know about the email feed! I will look into that :)
Thanks for this code, it works great!
Thanks for the code. It worked perfectly.
Permalink
Thanks – this is very useful. Going to use this for a project very soon. Most of the time I thought its only possible to import the posts, didn’t know a redirect (esp for individual posts!) was possible.
You’re welcomed.
Let me know how your project goes :)
Danny, thank you so much for this!
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 :)
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
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.
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!
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.
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!
Hi Charles,
Could you please give me an example?
Thanks for this code. We don’t want to use the http://www.sample.com/blog/2009/08/imported-post format including the date. We just want to use urls like this: http://www.sample.com/blog/imported-post. How might we do that?
Thank you very much for all of your help.
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?
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.
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.