Moving from Typepad to Wordpress

Ok, I made the switch. I just moved from my old TypePad account to my own installation of Wordpress. This is partly due to the fact that I just got myself a nice Hetzner Server and want to consolidate stuff on there.

One of the reasons I didn’t do this previously was that I didn’t want to manage my own server. But the thing is that Hetzner now provides RAID1 support and their customer support is top notch or so I am told. We’ll see how this goes.

One thing I wanted to post about to start with is how I (hopefully) managed to preserve all links and get relisted with the correct urls on Google. For that I modified the 404 script from my template.

The thing is that TypePad urls are in the form of http://url/year/month/15lettersoftitle.html . The permalinks I choose with Wordpress have the full title in the url though, so I somehow needed to move from the old to the new. The good thing is actually the .html at the end because it provides for a nice filter. And for the following to work you will have to have had an account at Typepad with the same domain as your new one, blog.thylmann.net in my case. It does not work for accounts that don’t allow you to do that.
So what did I do. Here are the steps.

First you get the filename from a request.

$url = basename($_SERVER['REQUEST_URI']);

Then you replace both the .html and any _ (the thing Typepad uses for spaces) with %

$file = str_replace(”.html”, “%”, “$url”);
    $file2 = str_replace(”_”, “%”, “$file”);

Now you need your database connection.

$link = mysql_connect(’localhost’, ‘user’, ‘pass’);
    mysql_select_db(’wordpress’, $link);

Next comes a wonderful query:

$query = “SELECT guid FROM `posts` WHERE `post_title` LIKE ‘$file2′ LIMIT 0 , 30″;
    $result = mysql_query($query);

What this does is get the exact new url to a post that fits with a search for the part of the title of the old Typepad url that is in the filename.html.

To do a little bit more filtering we need to find out the number of lines in the return.

$num_rows = mysql_num_rows($result);
First I then did some redirects to Feedburner for some Feeds on Typepad.

    if ( $url == “atom.xml” ) {
   
         header(”HTTP/1.1 301 Moved Permanently”);
         header(”Location: http://feeds.feedburner.com/owt”);
       }

    elseif ( $url == “index.rdf” ) {
   
         header(”HTTP/1.1 301 Moved Permanently”);
         header(”Location: http://feeds.feedburner.com/owt”);
       }
But if the number of rows is exactly 1, then we want to redirect to the new url.
    elseif ($num_rows == 1) {

       while ($row = mysql_fetch_assoc($result)) {
         header(”HTTP/1.1 301 Moved Permanently”);
         header(”Location:” . $row['guid']);
       }

For all else we display the standard error page.

    } else {
       old_code_here
    }

    mysql_close($link);

There you go. Now all your feeds should be fine, as well as your permalinks. The bots will see a nice permanent redirect and start indexing your new pages soon. I could still take a look at the categories but I think I will leave it at that.

Viewing 2 Comments

Trackbacks

blog comments powered by Disqus