Multiple domaine redirect main domain Htaccess

In almost all my project I have to manage multiple domaine for the same website.
.com .ca .org. co …

You can redirect in the htaccess all of your domain to the main domain.

4 simples lines of code in your .htaccess and it’s done.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.org$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

The first line is to start the Rewrite Engine
The second line is option for the Rewrite
The third line is the domain you need to redirect in this case .org
The fourt line is the domain you direct to, in this case www.yourdomain.com

In the situation that you have more the 2 domain use this code :

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.org$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.co$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

The first line is to start the Rewrite Engine
The second line is option for the Rewrite
The third line is the domain you need to redirect in this case .org note that this line finish with the OR [NC,OR]
The fourt line is the second domain that you need to redirect but this time at the end no OR
The fifth line is the domain you direct to, in this case www.yourdomain.com


Advertise with us!