I did a lot of searching for how to migrate my Blogger account so that:
- Each blog post at the old URL gets redirected to the same blog post on the new URL (e.g.
http://old-url.blogspot.com/bar
gets redirected to http://new-url.com/bar
).
- You do the redirect in a way that doesn't lose SEO rank. This means that JavaScript solutions (e.g. the accepted answer in this post) won't work, as you need a server-side generated
<link rel="canonical" href="http://new-url.com/bar"/>
tag in the <head>
.
I found no satisfying answers, so to help others in the future, I thought I'd add the hack I came up with here. The reason you need a hack is that blogger templates use some arcane XML syntax that allows basic variable lookups, loops, and if-statements, but as far as I can tell, there is no way to do string manipulation to accomplish the URL transformation in requirement #1 above. To work around this, you can generate a hard-coded list of if-statements that check every possible URL you care about and redirect it to the proper place. Something along the lines of:
<b:if cond='data:blog.canonicalUrl == "http://old-url.blogspot.com/url1"'>
<link rel="canonical" href="http://new-url.com/url1"/>
<meta http-equiv="refresh" content="0; url=http://new-url.com/url1"/>
<b:elseif cond='data:blog.canonicalUrl == "http://old-url.blogspot.com/url2"'/>
<link rel="canonical" href="http://new-url.com/url2"/>
<meta http-equiv="refresh" content="0; url=http://new-url.com/url2"/>
<b:elseif cond='data:blog.canonicalUrl == "http://old-url.blogspot.com/url3"'/>
<link rel="canonical" href="http://new-url.com/url3"/>
<meta http-equiv="refresh" content="0; url=http://new-url.com/url3"/>
<!-- And so on, one if-statement per blog post -->
If you can do basic scripting, you don't have to generate these if-statements (and there may be hundreds) by hand. Instead, you can export your Blogger posts to an XML file and write a simple script to read in each URL in that file and generate the if-statement above. I wrote a blog post about migrating from Blogger to GitHub Pages where I explain all the gory details and the Ruby script I used to generate the if-statements is available on GitHub. Note that this is a very hacky script customized for my blog, and it actually runs against the Jekyll conversion of the blogger XML export, but you can use it as a base to create your own script and avoid lots of weird blogger template error messages.