Moving? Redirect with htaccess and 301

If you've ever moved your site from one server to another, or changed domain names you know how difficult it can be to redirect all your old traffic to the new location. Here's a quick trick to make the transition totally seamless.

Redirect 301 / http://kdmurray.com/

This will redirect every URL beneath the root (" / ") to it's corresponding URL at mynewsite.net. So if you had a blog post from a couple of years ago that you migrated to the new domain, you can redirect the old URLs (which may have been cached in a search engine) to the new site to drive all that traffic to where it should be going.

In addition the 301 code (see HTTP 301) will tell web browsers & search engines that the page has been permanently moved which will help to ensure that the old site is no longer cached.

This should work with Apache on both Linux (OS X, unix etc.) and Windows.

Image Credit: Shannon K on Flickr