Successfully migrated blog!

At about 2 AM this night, I thought it would be a good idea to upgrade my ntnu hosted blog. (I really find myself quite bright at these hours). Surprise, surprise, the whole thing blew up.

«It doesn’t look like you’ve installed WP yet. Try running install.php.»

I do not really know what went wrong, but it did. I think the database tables got corrupted somehow. I wrote what I did on this page, but basically I did this:

  1. I dumped the database tables (had I done this before trying to upgrade, I could just have restored the whole thing to its previous state) using PhpMyAdmin
  2. Deleted the database, and made a new one with the same name
  3. Did a fresh install of wordpress
  4. Edited away all the «CREATE table ..» stuff from the dump file, and were left with just the «INSERT INTO …» statements.
  5. Imported this file into the new database using PhpMyAdmin

By now, I had a working blog again, but since I had been thinking about migrating it from self-hosting to wordpress.com for a while, I now exported the contents of the blog via WordPress’ Dashboard to a WordPress eXtended RSS (WXR) file, and imported this into the blog at oligofren.wordpress.com.

The blog was now up and running here, but I needed to redirect people coming to the old blog (via old search engine listings or old links) to the new one. This could have been as easy as putting this in my .htaccess file:
Redirect /kopseng/blogg https://oligofren.wordpress.com

but unfortunately, the import to the wordpress.com blog had also changed each blog entry’s number (because I have deleted or not published some older posts in the original database), so that what used to be post number 175 was now 146. This had to be fixed with a script.

Now I have newer written PHP, but I somehow managed to write the following ugly code, which did what it should do (rewrite the post number):


<?php
/* Redirect p=175 on the old blog to p=146 on wordpress.com */
$host = "oligofren.wordpress.com";
$new_p_var = $_SERVER[argv];
$new_p_var = substr($argv[0],2);
$new_p_var = $new_p_var - (175-146);

if ($new_p_var > 1) {
header("Location: http://$host/?p=$new_p_var");
}
else {
header("Location: http://$host");
}

exit;
?>

and put it in «/kopseng/content/redirect.php»

I then wrote this in my .htaccess file
Redirect /kopseng/blogg http://folk.ntnu.no/kopseng/content/redirect.php

This seems to do everything I wanted. Older posts may get the wrong address, but it was mainly the new posts that were important to map properly, since they are the ones getting attention.

Legg igjen en kommentar

Fyll inn i feltene under, eller klikk på et ikon for å logge inn:

WordPress.com-logo

Du kommenterer med bruk av din WordPress.com konto. Logg ut / Endre )

Twitter picture

Du kommenterer med bruk av din Twitter konto. Logg ut / Endre )

Facebookbilde

Du kommenterer med bruk av din Facebook konto. Logg ut / Endre )

Google+ photo

Du kommenterer med bruk av din Google+ konto. Logg ut / Endre )

Kobler til %s

%d bloggers like this: