code displaying on a laptop

Redirect Old Domain to New Domain via .htaccess

When you migrate a site from one domain to another, it is very important that you don’t break all the links that you built to your old domain. Proper redirection of all the pages on the old domain to the same location on the new domain will ensure that visitors to the old domain will end up in the right place.  A failure to redirect will result in a loss of visitors as well as search engine rankings.

We are assuming that your web server uses Apache for the purpose of this tutorial.  If you have not made any changes to your overall site structure, but have simply relocated the site in its current state, you can add the following lines to your .htaccess file located at the root of your old domain:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.olddomain.com$
  RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>

If you have made changes to your site structure, you can still use the lines above on your old domain, but you will also need to create redirects in the .htaccess file on your new domain to handle the specific site changes.

To redirect a single page to a new location on the same domain, use the following syntax:

Redirect 301 /old/old.htm http://www.domain.com/new.htm

It is possible to create rules that will redirect URLs that follow a certain pattern to a new location.  Since these rules involve complex regular expressions, we do not cover them here.  An SEO professional can help you create these more complex and situation-specific rules.  Just be sure that you use a 301 redirect for relocated content.  Any other type of redirect will not preserve your search engine rankings.