My Blogger to WordPress migration
Some years ago (around 2006), I experienced problems with the Blogger service while publishing via sFTP to my own domain. After reviewing some of the most-known CMS options I started working on migrating this blog to the WordPress software. My work back then consisted mostly on porting the look & feel of the blog to the WordPress templating system. Eventually, Blogger fixed their sFTP service and I no longer had the immediate need of completing the project, thus saving it for later. This worked fine until Blogger announced at the beginning of this year the deprecation of their FTP (and sFTP) protocols for publishing to non-blogspot.com domains.
Finding a solution was imminent this time and since I didn’t want to take the Blogger’s custom domains suggested approach, my only option was to finish the pending work with WordPress. After reading a bunch of how-tos and tutorials around the web I opted to use my own approach to get the job done. As many tutorials point out, the main issue with any Blogger to WordPress migration is maintaining the original permalinks from old posts as well as to properly handle redirects to the blog’s previous monthly archives, so links from search engines could continue to work.
Some tutorials suggest using the Blogger importer included in WordPress, with an extra plugin to ‘maintain Blogger permalinks’ for the imported posts. The importer, however, proved to be bad at the time of importing post’s comments, as it’s only able to import 50 comments at the most (for the whole blog!). For blogs with a lot of traffic and user comments (not my case) this isn’t a promising solution.
Other tutorials suggest using the blogger2wordpress utility to transform a Blogger export file into a WordPress extended RSS (WXR) file. The downside with this approach is that WordPress generates new permalinks for the imported posts, which aren’t exactly the same as those from Blogger and there is no plugin available to ‘maintain’ them as they were.
This is where a little Perl scripting came to the rescue. After taking a closer look to the WXR file generated by the blogger2wordpress service, I figured out how the WordPress-included WXR importer creates the new permalinks from the contents in the file: it takes the post titles and transforms them into a permalink structure. Fortunately, the WXR file contains the original Blogger permalinks for each post, so all I had to do was to replace the contents for each post title with the corresponding substring from the Blogger permalink and voila!, the WXR file was ready to be imported into the WordPress database and nothing else was needed to ‘maintain’ the original permalinks.
I think the script can be useful for those in a similar case who have access to a Perl interpreter, so here it is:
#!/usr/bin/perl -w
use strict;
my $file = shift;
open(F, "+<", $file) or die "can't read $file: $!";
my $out = '';
$/ = "<item>";
while (<F>) {
/\<link\>http\:\/\/.+\/\d{4}\/\d{2}\/(.+)\.html\<\/link\>/;
if ($1) {
my $slug = $1;
s/post_name\>.+\</"post_name\>".$slug."\<"/eg;
}
$out .= $_;
}
seek(F, 0, 0) or die "can't seek to start of $file: $!";
print F $out or die "can't print to $file: $!";
truncate(F, tell(F)) or die "can't truncate $file: $!";
close(F) or die "can't close $file: $!";
Save this code into a file such as replace_blog_permalinks.pl and change its permissions to make it executable. Then all you need to do to fix your blogger2wordpress WXR file is to run from the command line:
$ replace_blog_permalinks.pl YOUR_WXR_FILE.xml
I imported the resulting file into WordPress and once I had all of my posts and comments with the original permalinks in place, the rest of the setup consisted of setting up proper redirection to the blog archives: I created an archive/ directory under the blog/ directory (where I installed the WordPress files) and placed this into a .htaccess file inside of it:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/archive/
RewriteRule ^([0-9]+)_([0-9]+)_([0-9]+)_archive\.html$ /blog/$1/$2/ [R=301,L]
</IfModule>
I also setup proper redirection to the new feed locations as well as the usual WordPress rewrite rules to use custom permalinks for new posts. This was placed in a .htaccess file inside the /blog directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog
RewriteRule ^atom\.xml$ /blog/feed/atom [R=301,L]
RewriteRule ^rss\.xml$ /blog/feed [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
The last step in the WordPress configuration was to put the following custom structure into the Permalink Settings in the WordPress dashboard: /%year%/%monthnum%/%postname%.html
An extra step in my case was to copy the templates I ported years ago into the proper directory under the WordPress installation and use the theme manager to switch to my custom design. The result is what you see now in this page: my blog (and website) in exactly the same form as it has always been and with a new and powerful blogging engine underneath it. I hope my experience with this becomes useful to you 

























