Htaccess redirect entire site to new domain

If you want to move your website to new domain without hurting its SEO then use 301 redirect. Most simple way to do this is using htaccess mod_rewrite. Here I will explain 2 methods to redirect whole site to new domain.

A wrong way

Most webmaster uses following htaccess rule to move their website but this is a wrong way. This rule redirects each page on old domain to root of new domain (eg: http://olddomain.com/page.html to http://newdomain.com/) that affects indexed pages in search engine. This is not a SEO friendly way so I will not recommend it.

RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/ [R=301]

SEO friendly way

Another way to redirect is page by page. Following rule redirects each page on old domain to same page on new domain (eg: http://olddomain.com/page.html to http://newdomain.com/page.html).

This is the best way also recommended by Google

RewriteEngine on 
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

How to use?

Simply create a file name .htaccess in root of old website and put above code in that file

To check whether redirect is working properly use our URL redirect checker tool

Published by Sunny

A Mechanical engineer by education and web developer by passion and profession. He lives in Lucknow, India. Currently earning his livings by hitting keyboad. ;)

Join the Conversation

5 Comments

  1. Thanks for simple and uncluttered explanation. Quick question though if i may, when doing a 301 redirect from WordPress sites using the 301 redirection plugins will this have same effect as long as webmaster tools are notified of change of address too?
    Seems the simplest way to do it for people that dont want to mess around with htaccess

  2. Hey Anthony, I would not use a plugin for redirects unless you need to for a specific reason, because the more plugin you use the slower your website will become. If you can do a ridirect through htaccess then avoid using plugins, that will keep your site faster.

    Nice explanation of riderects though. Thanks for sharing it with us.

  3. This is incorrect. Both are SEO-Friendly rewrites. The only difference is in the last part with the “L” which means this is the last rule. If you had any other rewrites after the L nothing would work. Both are the same, one just means this is the last.

Leave a comment

Your email address will not be published. Required fields are marked *