[How To] Set htaccess 301 redirect to new domain

Share with all..

The .htaccess is a powerful file and it can be used in many ways to do settings related to Domain, PHP, Apache, etc..

In this post, you will learn how to set permanent redirection (301) for the visitors visiting domain example.com and www.example.com ( with and without wwww) to example1.com using .htaccess re-write rules.

Rewrite rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ "http\:\/\/example1\.com\/$1" [R=301,L]

Just put the above code in .htaccess file under document root of domain example.com and see the magic.

Note: Do not forget to replace domain names in the above rule as per your need.

Hope this helps!


Share with all..

About Abhijit Sandhan

Loves Open Source, Blogging, Traveling, Hiking and sharing Knowledge!

Leave a Reply

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