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


Liked It? Get Free updates in your Email

Delivered by feedburner

5 thoughts on “Htaccess redirect entire site to new domain

  1. Anthony Hayes
    #

    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

    Reply
  2. Gabor Andrasi
    #

    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.

    Reply
  3. Adam Sowers
    #

    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.

    Reply
    1. sunny Post author
      #

      See it again Adam.
      A wrong way redirects all page to new root domain. But SEO friendly way has page level redirection.

      Reply

Leave a Reply

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