How to redirect old domain to new domain using .htaccess file

When you migrate a site from one domain to another it is very important to move your traffic from your older domain to new domain. If you don’t take care of that you will lost your traffic and even existance in search engines. It is important that your all pages should be redirected to new domain properly otherwise you will lose your traffic.

There are different ways to redirect an old domain to new domain:

  1. Via .htaccess
  2. Via HTML
  3. Via JS
  4. Via PHP
  5. Via server

 

<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>

 

Related Posts