Phew, redirects are good!

So I think I’ve got all the old articles appearing at their old urls using .htaccess Redirect rules. This is a modification of a method described in the WordPress MT-Redirect method.

I had a directory of the old numerically-named MT archives, so I used the following script to create a .htaccess file:

for f in 000*html
do
 v=`basename $f .html`
 g=`echo $v | sed 's/^00*//;'`
 echo 'Redirect Permanent' /blog/archives/$f 'http://scruss.com/blog/index.php?p='$g
done

which looks like:

Redirect Permanent /blog/archives/000001.html http://scruss.com/blog/index.php?p=1
Redirect Permanent /blog/archives/000002.html http://scruss.com/blog/index.php?p=2
Redirect Permanent /blog/archives/000003.html http://scruss.com/blog/index.php?p=3
 ...
Redirect Permanent /blog/archives/000322.html http://scruss.com/blog/index.php?p=322

I put this .htaccess file in the root (top level) directory of my domain, and it all works! Everything I set out to do when reindexing my old MT entries has been completed — see, lookit: http://scruss.com/blog/archives/000214.html

Reindexing old MT entries

I’m not quite there yet, but I’ve got all my old MT articles with the same IDs as they had under that CMS. I basically used DrBacchus’ More about migrating from MT to WP method, but tried to integrate Scott Hanson’s Export from WordPress. It was not a complete success, but I’ll document what I did here in the hope that it’s useful.

DrBacchus was using an older version of MT, while I’m using the most recent version. I found that the file you have to edit to insert IDs is lib/MT/ImportExport.pm — not lib/MT/App/CMS.pm.

If you can avoid the temptation of adding blog entries to WP before importing from MT, do so. It’s a royal pain to add them later.

I used the WP MT-export module to export all my blog entries, then trimmed out the existing entries which had been entered in MT. I then added entry IDs to the export file (an awk one-liner: awk 'BEGIN{id=323;} {print;} /^STATUS: / {print "ID:", id; id++;}' worked for me, as my highest MT article ID was 322). I then joined the export files from MT and WP in one big ‘export.txt’ file.

If you have existing WP entries, you’ll have to get rid of them. I found that going directly into the database, and doing:

delete from wp_posts;
delete from wp_comments;

would do it.

Don’t forget to patch import-mt.php as per DrB’s instructions before importing.

Here’s where the pain comes in — WP wouldn’t import the text from the entries created in MT. It restored all the metadata, but not the content. So I had to manually patch in the entries from the export file.

I still have to work out rewrite rules for permalinks, but at least everything’s on the server where it should be. Maybe John’s Moved To WordPress rewrite rules will help me, as I think that my host (1and1) may not be doing entirely halal things with .htaccess support.

Seemingly innocuous comment spam

In the last 12 hours or so, I’ve been getting a new kind of comment spam on this blog. The text is fairly harmless: “very interesting article”, or “if you are using Linux or unix you can take a look at sourceforge.net”, but the link goes off to one of those pharmacy sites, or to russian car registration people.

Yes, I can run MT-Blacklist manually on them, and they are a bit lower key than the older style ones, but they’re still very annoying.

PNG graphics on Movable Type

My host doesn’t support the graphics library that Movable Type prefers for making thumbnail images. Six Apart shows you how to use NetPBM, which is supported.

I also discovered that the version I’m running doesn’t do PNG graphic handling. That’s easily fixed. In lib/MT/Image.pm, change the line:
my %Types = (jpg => 'jpeg', gif => 'gif');
to:
my %Types = (jpg => 'jpeg', gif => 'gif', png => 'png');

As a Perl guy, I’m mildly horrified with the way this code works, but it won’t bite most people.