Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

This causes problems for instance, if I want to send a user to 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, 
# and we want to redirect to one address.

RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [R,L]

RewriteCond %{HTTP_HOST} ^$
RewriteCond %{REQUEST_URI} !^/domainB/
RewriteRule ^(.*)$ /domainB/$1

This all seems pretty logical, and it works to an extent, BUT, every domain redirects to which of course is not good. domainD is NOT happy when they try to go to their site and see 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. will have a subdir of /root/domainB/

Thanks in advance.


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} ^/ [NC]
RewriteRule /domainB/(.*)$1 [R=301,L,QSA]

But now, it redirects everything to the /root/ website or

share|improve this question

3 Answers 3

This sounds like a perfect use for apache virtual sites. Do you have access to apache configuration files?

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /wwwroot/

# Other directives here


<VirtualHost *:80>
DocumentRoot /wwwroot/domainb/
# Other directives here


share|improve this answer
That would be a great solution if in fact I were in an Apache env. But no, it is Windows/IIS. Thanks though. – Gene R Oct 25 '10 at 14:01
@Gene R If this really is IIS, then you're barking up the wrong tree. Mod_rewrite is an Apache module. IIS has a completely different URL rewriting engine. – sysadmin1138 Oct 25 '10 at 22:54


#This first part checks for 'www' and appends it if its not there
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule .? http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]

#This next part is the magic that forwards to the appropriate subfolder including any
query string(s), etc.
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteCond %{REQUEST_URI} !^/domainX/
RewriteRule ^(.*)$ /domainX/$1

I thought this was it, but...

when I hit The resulting directory is www.domainX/domainX/somedirectory/ So, the rewrite is not working as I hoped.

I want it to physically hit that directory on the server, but not display/relay that subdir to the user, in essence, I want that subdirectory to be invisible. Ideas?

share|improve this answer

Maybe you need to change your last line: from:

RewriteRule ^(.*)$ /domainX/$1


RewriteRule ^(.*)$ /$1

I'm sorry I don't have enough reputation to comment on your answer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.