After having moved all my posts from Blogger to Ghost, I was left with the problem that Blogger doesn’t allow for 301 redirects. Granted, I don’t think I have that many incoming links out in the wild, but as a former SEO-guy, I wanted to do things right.
Unfortunately, Blogger doesn’t allow me to do things right (I need access to .htaccess). So the next best thing I could think of, was displaying a user-friendly message, redirecting users to my new blog.
First, I removed all content from my Blogger platform, and then I set a custom ‘page not found’ page. On that page, I wrote a little script that tries to determine what page on the Ghost platform the user wants to see.
As both platforms use the title of the post to create a URL, this is fairly easy, albeit not failproof. But it’s better than nothing.
var currentLocation = document.location.pathname;
var start = currentLocation.lastIndexOf("/");
var length = currentLocation.length - start;
var page = currentLocation.substr(start + 1, length);
var newPage = page.replace(/-/g, "_").replace(".html", "");
document.getElementById("newPageLink").href = "http://www.petermorlion.com/" + newPage;
A typical Blogger URL looks like this:
http://petermorlion.blogspot.com/2008/01/first-post.html
What the script does, is take the first-post.html
part, replace -
with _
and use that as URL, without the .html
. Effectively, this means the given URL maps to:
http://www.petermorlion.com/first_post
This works nice, except for some cases, where Blogger has shortened the URL or where the URL doesn’t map exactly to the title (because the title has changed).