Web Dev

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

Abhijit Sandhan

Love to Automate, Blog, Travel, Hike & spread Knowledge!

Related Articles

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button