Why can subdomains be accessed through the main domain URL?!?
So I have a cPanel account. Let's say for example the cPanel account is managing website: my-example-site.com
I create a subdomain for that site within cPanel the document root is NOT shared: staging.my-example.com
The File system for the staging site has the staging site located in:
public_html -> staging.my-example.com -> Files in this directory belong to the staging site.
I then put index.html in the root of the staging site directory. The question is WHY can the staging site be accessed with the following URL?
my-example.com/staging.myexample.com/index.html
It's draft?!? Why allow access to the subdomain website like this, why aren't they completely separate? Of course, the subdomain also works as expected and can still be access though: staging.myexample.com/index.html
I don't think search engines are going to really index this weird link and will index the subdomain properly but it's weird why this is a thing. The server runs NGINX in case Apache is handling things differently here.
-
Because that's the way that Apache works. To the main domain that's just another folder that can be served up, just like any other folder.
If you want to completely isolate them, you need to have the sub-domain/addon-domain above the public_html folder. Not all hosts will allow this (it's a configuration option on the server that your host decides on).
0 -
I'm using NGINX but I guess Apache is going to do the same.
I own and manage the WHM/cPanel server for a range of client sites. So if there is a way to change this behaviour in WHM options that would be great.
But looking at the domain documentation: https://docs.cpanel.net/cpanel/domains/domains/ it states Under the Create a New Domain: 'You cannot create a document root outside of the
public_html/
directory'0 -
If you have root access, go to tweak settings and the search for "Restrict document roots to public_html". Sounds like yours is on the default "On".
1 -
Sweet as a nut! Yeah the setting was on by default. Turned it off now
After switching it off the Domain options in the cPanel doesn't restricted to the Public_HTML, where the house icon is below used to say public_html before, but this is removed now
Many Thanks @ffeingol
1 -
No problem at all. There are so many tweak settings, it's easy to miss things like this.
2
Please sign in to leave a comment.
Comments
5 comments