[How To] Set htaccess 301 redirect to new domain

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 on Facebook0Share on Google+0Tweet about this on TwitterShare on StumbleUpon0Share on LinkedIn0Share on Tumblr0Pin on Pinterest0Email this to someonePrint this page

About Abhijit Sandhan

Abhijit Sandhan

Loves Linux, Blogging, Traveling, Hiking and sharing Knowledge!

Leave a Reply

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