Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having a problem making a sub directory act as the public_html for my main domain, and getting a solution that works with that domains sub directories too.

My hosting allows me to host multiple sites, which are all working great. I have set up a subfolder under my ~/public_html/ directory called /domains/, where I create a folder for each separate website. e.g.

  • public_html
    • domains
      • websiteone
      • websitetwo
      • websitethree
      • ...

This keeps my sites nice and tidy. The only issue was getting my "main domain" to fit into this system. It seems my main domain, is somehow tied to my account (or to Apache, or something), so I can't change the "document root" of this domain. I can define the document roots for any other domains ("Addon Domains") that I add in cPanel no problem. But the main domain is different.

I was told to edit the .htaccess file, to redirect the main domain to a subdirectory. This seemed to work great, and my site works fine on it's home/index page.

The problem I'm having is that if I try to navigate my browser to say the images folder (just for example) of my main site, like this:

then it seems to ignore the redirect and shows the entire server directory in the url, like this:

It still actually shows the correct "Index of /images" page, and show the list of all my images.

Here is an example of my .htaccess file that I am using:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteCond %{REQUEST_URI} !^/domains/yourmaindomain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domains/yourmaindomain/$1

RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteRule ^(/)?$ domains/yourmaindomain/index.html [L]

Does this htaccess file look correct? I just need to make it so my main domain behaves like an addon domain, and it's subdirectories adhere to the redirect rules.

share|improve this question

closed as off-topic by HopelessN00b, Jenny D, MadHatter, ptman, mdpc Feb 24 at 0:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

For the records: so far, this is working perfectly for a WordPress Multisite installation. – brasofilo Jan 31 '13 at 4:19

I'd call a rogue DirectorySlash on it.

  1. Does it only happen with directories?
  2. Does it only happen when there is no trailing slash (i.e. /images goes to /domain/yourdomain/images/, but /images/ is all right)?

In that case, there are 3 options:

  1. Make sure all links have the trailing slash (/)
  2. Set DirectorySlash off (will get you into double pages/dirs, from SEO standpoint not a nice one).
  3. Try to add the a RewriteRule just before your last index.html one: (thought up on the fly, don't know if it will work)

    RewriteCond %{REQUEST_FILENAME} -d  
    RewriteCond %{REQUEST_FILENAME} !/$  
    RewriteRule ^(.*) $1/  
share|improve this answer
I'm having the same issue, and as your answer suggests, it does indeed seem to be due to (lack of a) trailing slash. I'm interested in your third solution (aka solving it via additional RewriteRules) - though the listed rules don't seem to be working. I've tried to play with it some, but have been unable to get anything going. Any possible other suggestions that one might try? I've tried going through the mod_rewrite documentation but it's all pretty new/unfamiliar to me... – Metal450 Mar 14 at 21:17

One of your problems is your Regex: You are not escaping your dot. That means it will be taken as "any character" instead of just a dot. Instead of


you will need to have

share|improve this answer

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