Host Primary Domain from a subfolder

Posted by TandemAdam on Stack Overflow See other posts from Stack Overflow or by TandemAdam
Published on 2010-06-07T20:28:13Z Indexed on 2010/06/07 20:32 UTC
Read the original article Hit count: 308

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:

www.yourmaindomain.com/images/

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

www.yourmaindomain.com/domains/yourmaindomain/images/

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.)?yourmaindomain.com$
RewriteCond %{REQUEST_URI} !^/domains/yourmaindomain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domains/yourmaindomain/$1

RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
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.

© Stack Overflow or respective owner

Host Primary Domain from a subfolder

Posted by TandemAdam on Server Fault See other posts from Server Fault or by TandemAdam
Published on 2010-06-07T04:13:02Z Indexed on 2010/06/07 4:23 UTC
Read the original article Hit count: 310

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:

www.yourmaindomain.com/images/

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

www.yourmaindomain.com/domains/yourmaindomain/images/

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.)?yourmaindomain.com$
RewriteCond %{REQUEST_URI} !^/domains/yourmaindomain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domains/yourmaindomain/$1

RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
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.

© Server Fault or respective owner

Related posts about apache

Related posts about .htaccess