Redirect multiple domain names to single canonical domain for your site
This Apache rule describes how to have all selected domains and subdomains for a site come up in the site visitor's browser address bar as your one chosen canonical domain.
Here is an all-in-one-line approach:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.|)(example.com|anotherexample.com|yetanotherexample.ca) [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
On a Drupal site, your .htaccess will already have an IfModule mod_rewrite.c section, so putting these rules in directly below the existing RewriteEngine On line will work.
Here is also a one-at-a-time method:
<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect all users to access the site at 'www.example.com' (www prefix).
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.anotherexample\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^web\.yetotherexample\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^ftp\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
An implementation that preserves any subdomain while making the domain name consistent:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(.*)\.(activore\.com|activo\.re|actvr\.co) [NC]
RewriteRule (.*) https://%1.activore.net/$1
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*)\.(activore\.com|activo\.re|actvr\.co) [NC]
RewriteRule (.*) http://%1.activore.net/$1
Comments
Post new comment