Drupal to Wordpress migration

Posted by suvi under Software, Tricks

Hi all

Years ago I started with Drupal based websites. Now I am loving WordPress and I have converted most of my blogs to WordPress. Now is small howto, how I made that.
First thanks (and sources):
http://www.darcynorman.net/
,
http://blog.componentoriented.com/
and
http://dovdox.com/

So lets go forward. You are some website, what uses Drupal and You want to convert it to WordPress.

  • make dump of Your Drupal database – phpMyAdmin is good tool for that
  • make new database -lets say drupalmigration
  • install fresh WordPress. Use new database – lets say wordpress
  • Booth databases need to have same user!
  • Run fallowing SQL in phpMyAdmin :
# this script is modified after the recipe provided at
# http://spindrop.us/2006/05/19/migrating-from-drupal-47-to-wordpress
#
# as modified by:
# http://www.brendanloy.com/2007/02/wordpress-21-upgrade-problems.html
#
# and updated elegantly by:
# http://www.darcynorman.net/2007/05/15/how-to-migrate-from-drupal-5-to-wordpress-2/
#
# ...and then hacked to pieces and reassembled clumsily by Alan Dove,
# who can be found at http://dovdox.com
#
# this assumes that wordpress and drupal are in separate databases
# and that the wordpress database is named wordpress, while the
# drupal database is called drupalmigration.
#
# Finally, note that this script will not preserve posts' categories
# anymore - it will only move the posts and comments themselves.

# first, nuke previous content in wordpress database
use wordpress;
delete from wp_posts;
delete from wp_comments;

# posts
INSERT INTO
    wp_posts (id, post_date, post_content, post_title,
    post_excerpt, post_name, post_modified)
SELECT DISTINCT
    n.nid, FROM_UNIXTIME(created), body, n.title,
    teaser,
    REPLACE(REPLACE(REPLACE(REPLACE(LOWER(n.title),' ', '_'),'.', '_'),',', '_'),'+', '_'),
    FROM_UNIXTIME(changed)
FROM drupalmigration.node n, drupalmigration.node_revisions r
WHERE n.vid = r.vid;

# comments
INSERT INTO
    wp_comments
    (comment_post_ID, comment_date, comment_content, comment_parent, comment_author, comment_author_email, comment_author_url)
SELECT
    nid, FROM_UNIXTIME(timestamp),
    comment, thread, name, mail, homepage
FROM drupalmigration.comments ;

# update comments count on wp_posts table
UPDATE `wp_posts` SET `comment_count` = (SELECT COUNT(`comment_post_id`) FROM `wp_comments` WHERE `wp_posts`.`id` = `wp_comments`.`comment_post_id`);

# fix post slugs. first we have to remove the duplicate _____ chars, then replace that with a single - char
UPDATE wp_posts set post_name = REPLACE(post_name, '__', '_');
UPDATE wp_posts set post_name = REPLACE(post_name, '__', '_');
UPDATE wp_posts set post_name = REPLACE(post_name, '__', '_');
UPDATE wp_posts set post_name = REPLACE(post_name, '__', '_');
UPDATE wp_posts set post_name = REPLACE(post_name, '_', '-');

Change Your database names as needed. Also – chack that Your wordpress database prefix is wp_ – when not, then change it!

Now – when all is good, then lets go forward, with .htaccess file. Add to this file:

#
# Apache/PHP/Drupal settings:
#

# Various rewrite rules.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on

# Rewrite drupal urls to worpress
RewriteCond %{QUERY_STRING} ^q=node/(.+)$
RewriteRule ^(.*)$ http://yourwordpressdomain.com/?p=%1 [R=301,L]

# Forward RSS feed
RewriteCond %{QUERY_STRING} ^q=rss.xml$
RewriteRule ^(.*)$ http://yourwordpressdomain.com/?feed=rss2 [R=301,L]
RewriteCond %{QUERY_STRING} ^q=atom/feed$
RewriteRule ^(.*)$ http://yourwordpressdomain.com/?feed=rss2 [R=301,L]

</IfModule>

Change yourwordpressdomain.com with Your domain. Now all old Drupal links to Your WordPress works also!

One Response to “Drupal to Wordpress migration”

  1. Rick Says:

    Great script and thanks for updating it. One problem I had was that none of my Taxonomy (Drupal categories) came over. How can I fix that? Thanks.

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word