Moving Content to a new Domain and Keeping SEO

I recently killed my personal blog domain and transferred some of the existing articles over to this domain. One thing I wanted to make sure happened is anyone hitting any of the articles I had on the old site would be redirected to the appropriate article on the new site. Also, anyone hitting any other URL on the old site should be redirected to the homepage of the new site.

I was able to get this working by setting up an .htaccess and using mod_rewrite with Apache. This file is run before any files on the server are accessed, and tells the server what to do with the request before it would serve up the normal file.

Here's a truncated example of the file I had used:

RewriteEngine on

RewriteRule (notepad-tidy-for-xml/?) http://www.thomashunter.name/blog/notepad-tidy-for-xml/ [R=301,L]
RewriteRule (contact/?) http://www.thomashunter.name/contact/ [R=301,L]
RewriteRule (.*) http://www.thomashunter.name/ [R=301,L]

A 301 redirect is a permanent redirect, use it for a permanent change. If you want to temporarily redirect users, use a 302 redirect instead.

Tags: #webserver
Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript, published a book on microservices, and is an organizer of Nodeschool SF.