Convert a Nucleus blog to Wordpress

As you could read in my previous post, I converted my weblog from Nucleus CMS to Wordpress. This article illustrates how I did it.

Import Nucleus content

I started by looking for a converter for Nucleus to Wordpress. I was happy to find one for Wordpress 2.1. Because I wanted to do most of the work while being offline (on the train), I then setup a local environment. This was very easy with XAMPP. After having the Magic LAMP running, I created a local database and imported all my Nucleus tables. Then I installed Wordpress 2.1 in my local environment and started the conversion. It must have been my lucky day, everything seemed to work and my Nucleus content (items, comments, users, trackbacks etc) were imported into Wordpress. After the import i could easily update Wordpress 2.1 to 2.7.

The Theme

The next important step: convert my carefully crafted ( ;-) ) Nucleus skin to a Wordpress theme. I thought this would be rather time consuming, but actually it only took me 10 hours (on the train) to completely convert my skin. I started from the default Wordpress theme, which was very helpful to see how everything works. Other details in this step are less important, because they are specific to my theme.

Cool URI's never change

Because I get quite a few incoming links from Google and other sites, I wanted to keep the Nucleus FancyURL's working and redirect visitors of the 'old' urls to the new ones. To get this working I took a few steps. A FancyURL in Nucleus looks like http://budts.be/weblog/item/123. However a url in wordpress looks like http://budts.be/weblog/2009/01/my-post. So first I had to find the mapping between the old Nucleus ID's every item and it's new Wordpress permalink. To do so I used a hackish SQL query on the database:

select CONCAT('$items[',n.inumber,'] = "',year(w.post_date),'/',
month(w.post_date),'/',w.post_name,'/";') from wp_posts w,
nucleus_item n where n.ibody = w.post_content

The query missed a few items, but i guess a 90% ratio is good enough (the earth won't end if a few items aren't correctly mapped, right?). This query gives output such as:

<?php
$items[549] = "2005/10/het-wordt-weeral-herfst/";
$items[550] = "2005/11/digg/";
$items[551] = "2005/11/how-to-tuesday-disable-autorun-on-windows/";

This is the code that I copy pasted in a new PHP-file with the name 'redirector.php'. This PHP-script looks like:

<?php
if ($_GET["type"] == "category") {
    redirectCategory(intval($_GET["id"]));
}
if ($_GET["type"] == "item") {
    redirectItem(intval($_GET["id"]));
}
print "euhr.. hmm yeah.. this doesn't look very good.";


function redirectCategory($categoryID) {
    $categories = array();

    $categories[1] = "general/";
    $categories[2] = "eten/noodles/";
    ...
    $categories[24] = "muziek/";

    if (array_key_exists($categoryID, $categories)) {
        header('Location: /weblog/category/'.$categories[$categoryID]);
    } else {
        header('Location: /weblog/');
    }
}

function redirectItem($itemID) {
    $items = array();

    $items[26] = "2003/09/pingtest/";
    $items[27] = "2003/09/dit-is-cht-gestoord-maar-wel-grappig/";
    $items[28] = "2003/09/nog-meer-noodles/";
    ...
    $items[583] = "2008/04/antwerp-10-miles/";
    $items[585] = "2008/05/een-huis-kopen-t-is-niet-gelijk-naar-den-bakker-gaan/";

    if (array_key_exists($itemID, $items)) {
        header('Location: /weblog/'.$items[$itemID]);
    } else {
        header('Location: /weblog/');
    }
}

Still one thing about the SQL query: it produces dates such as 2009/2/foo-bar, while it should be 2009/02/foo-bar (although both seem to work in Wordpress). So before pasting the output of the query in the redirector.php script I first did a find/replace (with regular expressions) on the output with jEdit, by searching for "200([0-9])/([0-9])/ and replacing it with "200$1/0$2/. For the category mapping (also in the redirector.php-script) i used a similar query.

The next step is some .htaccess-magic. So before the first default Wordpress RewriteCond I added the following rules:

# cool uri's never expire (old nucleus blog url's)
# fancy urls
RewriteRule blog/[0-9]+/item/([0-9]+).*$    redirector.php?type=item&id=$1      [R,L]
RewriteRule blog/.*$                        /weblog/                            [R,L]
RewriteRule member/.*$                      /weblog/                            [R,L]
RewriteRule archive(/[0-9])?/([0-9]{4})-([0-9][0-9]).*$ /weblog/$2/$3/          [R,L]
RewriteRule item/([0-9]+).*$                redirector.php?type=item&id=$1      [R,L]
RewriteRule category/([0-9]+)(/.*)?$        redirector.php?type=category&id=$1  [R,L]
# feeds
RewriteRule atom\.php                       /weblog/feed/atom/                  [R,L]
RewriteRule xml-rss.?\.php                  /weblog/feed/                       [R,L]
RewriteRule xml-rss-comments\.php           /weblog/comments/feed/              [R,L]

These rules try to rewrite as much as possible, sometimes by redirecting to the redirector.php script to find the correct mapping. If a good redirect can not be done or found (in case of a mapping), the visitor is redirected to the home-page.

I guess that describes the steps I took to convert my blog from Nucleus to Wordpress. Now it is plugin-playing and -discovering time :).

Comments

Avatar

krzychu on 2009-03-12 19:17 reply

Your tips about

Your tips about importing/migration from Nuclues to WP works very well. Thank you!

One question left about your redirector hack: is it working even if nucleus files and database is missing?

Avatar

Misha on 2011-12-29 13:46 reply

Hello, thank you very much

Hello, thank you very much for this post! I have just switched from Blog:CMS, which is based on Nucleus onto Worpdress. I have even changed the domain of my site so now I would have to redirect my old Nucleus site onto new WP site. For that I would like to implement first rel=canonical and then 301 redirects. To make it work in the best way I would like the permalink structure to match but I really couldn't find a solution for that until I have found your post. Right now I am using mysite.com/blog/?item=name-of-the-post on Nucleus site and mysite.com/blog/year/month/name-of-the-post on the WP site. All posts IDs remained the same. Could you please help me with creating the SQL query, php redirect and htaccess code? I would be very thankful for your help as I am a real newbie to all of these things and it's been really difficult for me to make the whole migration, etc. Thank you very much! All the best from Misha

Comment Atom Feed