We Recommend

Pro Apache Pro Apache
In addition to installation, maintenance, and deployment, the book demonstrates how to configure Apache to use Perl, PHP, and Python as server-side scripting languages. And unlike other books on Apache, Pro Apache provides comprehensive information on both major revisions - 1.3 and 2.0 - of the software.


Posted By

torkil on 01/16/08


Tagged

url modrewrite htaccess apache www seo domains


Versions (?)


Who likes this?

7 people have marked this snippet as a favorite

jonhenshaw
basicmagic
glex
cyrilbatillat
cbrant
snucko
torkil


Forward from domain aliases to main domain


Published in: Apache 


URL: http://www.torkiljohnsen.com/2008/01/16/some-easy-use-of-mod_rewrite/

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 and_so_on.com just has [NC].

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


  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 (.*) http://maindomain.com/$1 [R=301,L]
  8. # END forward from domain aliases

Report this snippet 

You need to login to post a comment.