in X-Geek

Drupal To WordPress Migration

I kicked off the new WordPress version of MT.Net late last night. I didn’t start out with the plan to do it but once I saw how easy it was I got hooked on it and didn’t stop until late last night.

I first began using WordPress back at my last job, where I updated a Lyceum server with news about the company. I like WordPress’s look. Drupal is a bit too complicated for a simple blog like mine.

The real key was the script I found on D’Arcy Norman’s blog. D’Arcy did the migration a few weeks ago and detailed it all on his blog. He made generous use of Panayotis’s detailed instructions, so it was actually a group effort.

The SQL applied surprisingly cleanly, though I found that all the MT.Net users were not brought over. For that, I used the wp_users snippet from this migration script:

INSERT INTO wp.wp_users (
ID, user_login, user_pass, user_nickname, user_nicename, user_email, user_registered)
SELECT uid, name, pass, name, name, mail, FROM_UNIXTIME(created)
FROM drupal.users
WHERE uid > 1;

Once that was run, the database parts were complete.

The next step was to migrate all the links from the old Drupal database t the new one. This takes some time, so some Apache Rewrite magic was needed. After much trial and error, I came up with these rules which seemed to be as close as I could get to Drupal backward-compatibility. This of course can go into your site’s .htaccess file or in your site’s Apache VirtualHost configuration file:

RewriteEngine OnRewriteBase /
# Drupal nodes -> WP nodes
RewriteCond %{QUERY_STRING} ^q=node/([0-9]+)$ [OR]
RewriteCond %{REQUEST_URI} ^/node/([0-9]+)$
RewriteRule .* /?p=%1 [R=301,L]

# Previous entries, Drupal -> WP
RewriteCond %{QUERY_STRING} page=([0-9]+)$
RewriteRule .* /index.php?paged=%1 [R=301,L]

# Drupal taxonomy -> WP categories

RewriteCond %{QUERY_STRING} ^q=taxonomy/term/([0-9]+) [OR]
RewriteCond %{REQUEST_URI} ^/taxonomy/term/([0-9]+)$
RewriteRule .* /?cat=%1 [R=301,L]

# RSS feeds, Drupal -> WP feeds

RewriteCond %{QUERY_STRING} ^q=node/feed [OR]
RewriteCond %{REQUEST_URI} ^/node/feed$ [OR]
RewriteCond %{QUERY_STRING} ^q=rss.xml
RewriteRule .* /?feed=rss2

I am still looking into the best way to tie my site’s feed to Feedburner but I should have that fixed shortly. I also will spruce up the theme to make it look better.

Y’all poke around and let me know if I missed anything. And thanks for reading!

  1. Nicely done! I was wondering how the old feed was working. That’s really cool. (And, now I don’t have to bug you about fixing the drupal theme anymore. 🙂

Comments are closed.