How can I isolate addon domains under public_html from the main domain?

流过昼夜 提交于 2021-01-29 20:46:09

问题


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...

  1. one.com is tied to the hosting plan, and is stored in public_html directly.

  2. two.com is setup as an addon domain and is stored in public_html/two.

  3. three.com is also setup as an addon domain and is stored in public_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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!