Redirecting old blog posts to a new domain

The basic idea, and why you'd want to do this

I had a small blog with a few posts, and decided I didn't want to maintain the site anymore (not to mention my Wordpress install on my host was really slow). However, I still wanted the posts accessible on whatever blogging platform I decided upon... here's looking to you, Roon.

The first step

You need to re-create, import, or otherwise get your old posts to the new platform before you destroy the old blog. You'll also need to write down the original links.

If you're using Roon, you'll hopefully be able to change the date of these posts at some point, to match when you originally posted them.

The code

For something so simple, there are a remarkable number of ways to implement 301 redirects. After looking at several sites and trying a few things, I know this way works. Hopefully it'll save someone time down the road.

In your .htaccess file:

Options +FollowSymLinks
RewriteEngine on

# Redirect the home page
RewriteRule ^$ http://dhartweg.roon.io [R=301,L]

# Redirect the previous posts
RewriteRule ^2012/05/overview-of-global-variables-in-php$ http://dhartweg.roon.io/global-variabels-in-php [R=301,L]
RewriteRule ^2012/06/jquery-ui-drag-and-drop-to-change-parent-div$ http://dhartweg.roon.io/jquery-ui-drag-and-drop-to-change-parent-div [R=301,L]
RewriteRule ^2012/11/xcode-4-subversion-server$ http://dhartweg.roon.io/xcode-4-subversion-server [R=301,L]

You would simply insert an additional RewriteRule for each post you want to redirect, supplying the original url, and the new url. Anything else will be redirected to whatever landing page you designate.

As a side note, Regex is still difficult to wrap my head around. Luckily, I stumbled across this article written by nikic the other day that explains things very well.

Let me know if I'm wrong!

I know this works for me. I also know, as with everything, there are other ways to make it happen. If you have alternatives (or think there's a huge error in how I went about this), please let me know!

Share Comment on Twitter