.htaccessHTMLPHP

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

0
524
2018 / 02 / 07

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>

 

Hi, I am a full-stack web developer with 5+ years of experience in working with different web technologies. Do you want to ask something? just send me a message through the contact form. Please visit my portfolio at hamzamehmood.com. Thanks