Redirecting a Wordpress Site

Last week I decided to completely move my blog over to bitnode.net. I created a post in the old location with the details of the move and watched my viewer metrics slowly shift sites. However, Google is still indexing my old site and it is still showing up at the top of the results while this new blog is just hanging around on page four. This makes for a very sad day for all (or possibly just me).

With that, I decided to do a redirect. There are several options for a redirect, but what I wanted was a bit different than the typical domain forward. I wanted to be able to keep my post locations, but have the domain name change. Since the paths to my posts are the same format between the old location and the new location, doing a simple append to the redirect url would suffice. Here’s how I did it.

At the top of my header.php file (yep, WordPress), I added the following lines…

<?php header("HTTP/1.1 301 Moved Permanently");
header('Location: http://bitnode.net/'.$_SERVER["REQUEST_URI"]); exit();
?>

Since this is in my header file, it loads on every page. What’s nice about this solution is that it takes the path to the current page and appends it to bitnode.net redirect location, so if your source and destination URI formats are the same, it will be a seamless redirect.

This solution works well, but does anyone have any other solutions that would also work? It never hurts to know all the different ways after all.

Edit: As it turns out, you can do the same thing from WordPress to Drupal. They evidently support the same URI formats.

Category:WordPress Category:PHP