Easy 301 Redirect for Whole site with Htaccess

Posted by: Alex on February 19, 2014

If you ever change your website URL/Domain, you will want to 301 your old address so that links remain intact that people may have bookmarked/saved, and to transfer the power from Google search results.

The easiest way to do this is with the .htaccess file:

The very simplest code that will 301 your whole site is as follows.

Redirect 301 / http://www.MyNewSite.com

However on shared hosting the above can play up sometimes, so I generally prefer the following as it is more declarative:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^oldsiteaddress\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldsiteaddress\.co\.uk$
RewriteRule ^(.*)$ "http\:\/\/www\.MyNewSite\.com\/$1" [R=301,L]