问题
I am using Directnic to host multiple websites. Directnic, like many hosts, requires each website to be placed under the /home/<user>/public_html
directory. And this works. My problem is that some websites are accessible from the "main" domain.
Here is an example of what my configuration looks like...
one.com
is tied to the hosting plan, and is stored inpublic_html
directly.two.com
is setup as an addon domain and is stored inpublic_html/two
.three.com
is also setup as an addon domain and is stored inpublic_html/three
.
This all works as expected, all three websites show three different websites and all have three different document roots, so everything works nicely.
My problem is that I can access the files for two.com
and three.com
by going to http://one.com/two/
, etc, and I don't want this, I want them to be more isolated.
What configurations might I be able to make to hide these files from one.com
?
My host uses Apache and cPanel, but I don't have access to specific conf files, so I can't create virtual hosts. Maybe some .htaccess trickery?
回答1:
This is the way cPanel works. You cannot isolate it 100% and you will not get configuration access to add virtualhost entry. It is being managed by your service provider.
You can certainly restrict the access for HTTP. You can add rewrite rule in your subfoldess (in above example two and three folder). You can try the following .htaccess rewrite rules to prevent direct access from main domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/addon2/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/addon3/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
Once you add above rule, your main domain should not be able to access addon folder usin g HTTP. It should show 404 error page.
来源:https://stackoverflow.com/questions/57228822/how-can-i-isolate-addon-domains-under-public-html-from-the-main-domain