HowTo: Send all Traffic From a Domain to New Domain Root With htaccess

Whenever in need to finish up with a website and send every traffic going to that website to a new domain (not matching any folders, subdomains, post titles) then .htaccess comes in handy.

The scenario

Let’s say you have a website http://tom.ee and you really need to redirect all the traffic coming to it to another domain name, let’s say http://tompai.pro. You want everyone that visits http://tom.ee or any of it’s pages like http://tom.ee/about to land (be sent) on your new website homepage (http://tompai.pro).

To accomplish this (let’s assume you’re running Apache) use a .htaccess rule.

.htaccess is a file that you will normally find in your website’s public_html folder that regulates a lot of things how your website gets displayed.

.htaccess file in a WordPress installation in an FTP program remote files list
.htaccess file in a WordPress installation in an FTP remote files list

SOLUTION

  1. Download the .htaccess for editing to your desktop and open it with Notepad, Notepad++ or similar text editors.
  2. To the top first lines of it put this code:

    Options +FollowSymLinks -MultiViews
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^(www\.)?tom\.ee$ [NC]
    RewriteRule ^ http://tompai.pro [R=301,L]

  3. Replace tom and ee with your old domain name and tompai.pro with your new domain name that you want the traffic to go to.
  4. Then save the file, bear in mind that .htaccess needs to be saved WITHOUT A FILENAME EXTENSION. To do this put the filename in quotes in your save dialog as so: “.htaccess” or just hit Ctrl+S after you’ve done the editing.
  5. Upload the edited .htaccess to your webserver and test the website and it’s sub-pages, do they redirect as supposed to.

Explanation: this code uses 301 response code to redirect traffic. This means “moved permanently”. Google will read and remember this and consider your new website as the heir of your old website. Using a server side redirect (like .htaccess) is recommended by Google to keep your SEO rankings.

 

To see if the redirect works for me, test any link on http://tom.ee , like http://tom.ee/contact etc.

Hope this helps!

Additional reading:
https://stackoverflow.com/questions/8819706/redirect-all-traffic-to-root-of-another-domain

 

 

Post Author: Tom Pai