How to move a WordPress installation and keep linkjuice

Recently I went freelance and decided to rebrand myself – thus the need to move my blog from one domain to another. Of course, that meant moving the content to a new WordPress install, but also – since my old blog had a handy pagerank of 5 and lots of incoming linkjuice – I needed to redirect all this to my new blog. To make things even more complicated, I had decided to go away from my original link-format of “bie.no/category/second-category/blog-post-title-here” to the shorter “bybjorn.com/10”. Needless to say, I did not want to break existing links. It turned out to be a whole lot easier than expected.

First off, the WordPress export / import tool works like a charm1. Second, I wrote a simple .htaccess to forward everything to an index.php which then again redirects everything (including the query string) to the new url. That means bie.no/category/blog-post-here for example will be redirected to bybjorn.com/category/blog-post-here .. and WordPress is smart enough to understand the original link-format, and then redirect to the new one I’ve chosen for this blog. So the user will end up on bybjorn.com/10, all incoming links work and all link-juice transferred (using 301 redirects).

index.php:

header ('HTTP/1.1 301 Moved Permanently');
 $i = $_GET['i']; if($i != "") {$location = "http://www.bybjorn.com/" . $i;
 } else { $location = "http://www.bybjorn.com/";}
 header ('Location: '.$location);

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?i=$1 [L]

Here’s the process in easy to understand list-format;

  1. Install WordPress on the new location
  2. Use WordPress’ built in export tool to do a full export of your original blog
  3. Upload the export file and use the same tool in the WordPress admin to import the data to the new blog
  4. Download and activate any plugins you had on your original blog (akismet, textile, etc)
  5. May be the case: go through all the blogposts and fix direct links to files etc. you have posted on your old domain (if such exists)
  6. Delete your old blog, and upload this new index.php and this .htaccess

Enjoy!

[1] (unless you have large amounts of data)