How to Redirect an Entire Site Using HTAccess

If you have a website you want to move to a new domain, one of the easiest and best ways to do it is with a 301 redirect in an .htaccess file in your web server root.

301 Redirects are Important

It's important that you use a 301 redirect rather than a meta refresh or other type of redirect. This tells search engines that the pages have been permanently moved to a new location. Google and other search engines will then update their indexes to use the new domain without changing your indexing values.

So, if your old website was ranking fairly well in Google, it will continue to rank well after the redirect is indexed. I have personally used 301 redirects for many of the pages on this site with no change in their rankings.

Difficulty: Average

Time Required: 15 minutes

Here's How:

  1. Place all your content on the new domain using the same directory structure and file names as the old domain. This is the most important step. In order for this 301 redirect to work, the domains need to be identical in file structure.

    You might also consider putting in a noindex, nofollow robots.txt file on this new domain until you've got the redirect set up. This will insure that Google and other search engines don't index the second domain and penalize you for duplicate content. But if you don't have a lot of content, or can get all the content copied over in a day or so, this isn't as important.

  2. On your old domain website, open up the .htaccess file in your root directory with a text editor – if you don't have a file called .htaccess (note the dot at the front), create one. This file may be hidden in your directory list.

  1. Add the line:

    redirect 301 / http://www.new domain.com/

    to the .htaccess file at the top.

  2. Change the URL http://www.new domain.com/ to the new domain name you're redirecting to.

  3. Save the file to the root of your old website.

  4. Test that the old domain pages now point to the new domain.

Edited by Jeremy Girard