I've got a pretty unique issue (at least i've never seen it before).
I have an account on a shared host, where I host multiple domains.
So, domain A (the main acct) is the root folder on the wwwroot
domains B-D are subfolders of the root
I am currently using Coldfusion redirects to check cgi.server_name and send to the correct subfolder. But, I end up with DomainB.com/domainB/index.cfm
This causes problems for instance, if I want to send a user to DomainB.com/admin/ The server can't find it because the /domainB/ isn't in the path.
So I want to use mod-rewrite to address this issue. I thought I found a resolution with:
# If same website is accessible by different addresses, like domain.com,
# www.domain.com and we want to redirect to one address.
RewriteCond %{HTTP_HOST} !^www.domainB.com$ [NC]
RewriteRule ^(.*)$ http://www.domainB.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^www.domainB.com$
RewriteCond %{REQUEST_URI} !^/domainB/
RewriteRule ^(.*)$ /domainB/$1
This all seems pretty logical, and it works to an extent, BUT, every domain redirects to www.domainB.com which of course is not good. domainD is NOT happy when they try to go to their site and see www.domainC.com instead.
Anyone have an idea what i'm doing wrong, or better yet, how to make this dynamic? Assuming every subdirectory is named the same as the domain name. I.E. www.domainB.com will have a subdir of /root/domainB/
Thanks in advance.
EDIT
Ok, this is what I have now (just appending to make sure it matches yours)
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule .? http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]
RewriteCond %{REQUEST_URI} ^/domainB.com [NC]
RewriteRule /domainB/(.*) http://www.domainB.com/$1 [R=301,L,QSA]
But now, it redirects everything to the /root/ website or www.domainA.com