I had a problem in that the subdirectory acts like public_html for my main domain and gets a solution that also works with similar domain directories.
Background
My hosting allows me to host several sites that work great. I created a subfolder under my ~ / public_html / directory / domains / , where I create a folder for each individual site. The folder structure on my server looks something like this:
- public_html
- domains
- websiteone
- websitetwo
- websitethree
- ...
It makes my sites nice and neat. The only problem was that my "primary domain" fit into this system. It seems that my main domain is somehow attached to my account (or to Apache or something else), so I can not change the "document root" of this domain. I can determine the roots of the document for any other domains ("Addon Domains") that I add to cPanel without any problems. But the main domain is different.
Problem
I was told to edit the .htaccess file to redirect the main domain to a subdirectory. This seemed to work fine, and my site works fine on the home / index page.
The problem that I encountered is that if I try to go to my browser to say a folder with images (for example) of my main site, for example:
www.yourmaindomain.com/images/
then it seems to ignore the redirect and show the entire server directory in the url, for example:
www.yourmaindomain.com/domains/yourmaindomain/images/
It still shows the correct Index / Image page and shows a list of all my images. This is just the "pretty" url of this problem.
An example of my .htaccess
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]
Is this htaccess file correct? I just need to make my primary domain behave like an addon domain, and its subdirectories adhere to the redirection rules.
source share