Forward from domain aliases to main domain

/ Published in: Apache
Save to your folder(s)

Forward users from your alias domains to your main domain automatically. Nice to have if your site has got one or more aliases. Notice that all the domain aliases have [NC,OR] at the end of the line, while the last alias just has [NC].

Insert the code in your .htaccess-file in your website's root folder.

Copy this code and paste it in your HTML
  1. # forward from domain aliases
  2. RewriteEngine On
  3. RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC,OR]
  4. RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com [NC,OR]
  5. RewriteCond %{HTTP_HOST} ^(www\.)?domain3\.com [NC,OR]
  6. RewriteCond %{HTTP_HOST} ^(www\.)?and_so_on\.com [NC]
  7. RewriteRule (.*)$1 [R=301,L]
  8. # END forward from domain aliases


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.