Domain to Domain rewrite (advanced case)

Using a single web hosting account to host multiple sites

Domain to Domain rewrite (advanced case)

Postby nf » Wed Jan 14, 2009 12:31 pm

I have a server on which I handle more than one domain; all of them point to the same folder.
I also rewrite subdomain to domain as a script parameter (PARAMETER.domain.com to domain.com/script.php?id=PARAMETER) for all domains I use. My mod_rewrite part of .htaccess looks like:

Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.(domain\.com|domain\.eu|domain\.net)$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.(domain\.com|domain\.eu|domain\.net)$ [NC]
RewriteRule ^$ /script.php?id=%2 [QSA,L]
RewriteRule .* - [L]


The issue is with Google indexing service which doesn't index content if is the same on more than one domain. I can simply use one domain (eg. com) as main and redirect remaining ones (eu, net) to that one. Problem then is that I loose subdomain as a script parameter solution for remaining domains (eu, net).

So my question is - how to redirect:

Code: Select all
domain.eu, domain.net to domain.com (with and without www.)
and
SUBDOMAIN.domain.com, SUBDOMAIN.domain.eu, SUBDOMAIN.domain.net to domain.com/script.php?id=SUBDOMAIN (with and without www.)


Thank you!
nf
 
Posts: 12
Joined: Thu Dec 04, 2008 6:26 am

Postby richardk » Wed Jan 14, 2009 2:00 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.(eu|net)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+\.)example\.(eu|net)$ [NC]
RewriteRule ^$ http://%2example.com/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule ^$ /script.php?id=%2 [QSA,L]


Or two remove all www.s try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.(eu|net)$ [NC]
RewriteRule ^$ http://example.com/ [R=301,L]

RewriteCond %{HTTP_HOST} ^(w)ww\.([^\.]+\.)example\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+\.)example\.(eu|net)$ [NC]
RewriteRule ^$ http://%2example.com/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.example\.com$ [NC]
RewriteRule ^$ /script.php?id=%2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 21 guests

cron