Forum Moderators: phranque
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
#
# Externally redirect to canonical www.maindomain.com hostname,
# removing optionally-appended FQDN token and port number
RewriteCond %{HTTP_HOST} ^([^.]+\.)*maindomain\.com [NC]
RewriteCond %{HTTP_HOST} !^www\.maindomain\.com$
RewriteRule ^(.*)$ http://www.maindomain.com/$1 [R=301,L]
#
# Externally redirect to canonical www.newdomain.com hostname,
# removing optionally-appended FQDN token and port number
RewriteCond %{HTTP_HOST} ^([^.]+\.)*newdomain\.com [NC]
RewriteCond %{HTTP_HOST} !^www\.newdomain\.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
#
# Externally redirect to canonical otherdomain.net hostname,
# removing optionally-appended FQDN token and port number
# (Note that this hostname is canonicalized to the NON-www variant)
RewriteCond %{HTTP_HOST} ^([^.]+\.)*otherdomain\.net [NC]
RewriteCond %{HTTP_HOST} !^otherdomain\.net$
RewriteRule ^(.*)$ http://otherdomain.net/$1 [R=301,L]
#
# Internally rewrite requests for all but canonical main domain (or blank hostname) to hostname-
# based subdirectory under "addons" subdirectory, unless we've already done this rewrite
RewriteCond $1 !^addons/
RewriteCond %{HTTP_HOST} !^www\.maindomain\.com$
RewriteCond %{HTTP_HOST} ^((www\.)?[^.]+\.([a-z]{2,6}|co\.[a-z]{2})$
RewriteRule ^(.*)$ /addons/%1/$1 [L]
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^www\.newdomain\.com
RewriteRule ^(.*) http://www.example.com%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} !^www\.(example|newdomain)\.com
RewriteRule .* http://www.example.com%{REQUEST_URI} [R=301,L] RewriteCond %{HTTP_HOST} !^www\.(example|newdomain)\.com
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L] RewriteCond $1 !^addons/
RewriteCond %{HTTP_HOST} !^www\.maindomain\.com$
RewriteCond %{HTTP_HOST} ^www\.newdomain\.com$
RewriteRule ^(.*)$ /addons/www.newdomain.com/$1 [L]