Hello, before I start I'm aware of this post,
My request is that subdomains should be isolated from the domains and not be just a folder under public_html folder.
A case of example, I create subdomain.example.com and I don't want it to be accessible from example.com/subdomain
A more realistic case as a web developer I build RIA apps where lot of times I need something like api.example.com sso-auth.example.com etc
if we say that 1 RIA app has the following structure:
Then if we say that we have the following domain / subdomains: example.com, api.example.com and sso-auth.example.com we will have this structure (I exclude folders like private_html public_ftp etc since they are not needed in this example):
With the above we will be able to access our main application from example.com domain, our API container from api.example.com and example.com/api and our sso authentication system from sso-auth.example.com and example.com/sso-auth
What we end up is double log and statistic records because of the way subdomains treated but the worst is that we end up with this structure:
So where is the problem with this structure? from security perspective folders like libraries and src should not be under public folder for any reason so having those folders under public folder is a great security risk. From architecture perspective the document root for any cases should be public_html so the document root for the domain / subdomains should be like this:
example.com -> example.com/public_html
api.example.com -> example.com/public_html/api/public_html
sso-auth.example.com -> example.com/public_html/sso-auth/public_html
The above is actually meaningless since even if subdomains will have their own document root they will be still accessible by their parent domain which is example.com
I could provide more cases in order to prove wrong the current subdomain treatment if you like.
For all the above I know there are ways to change for example customize vhosts, .htaccess files in order to deny example.com/subdomain type access and adding custom document root and etc but the case is to do those things automatically.
From what I though the best way to treat subdomains would be same as domains, for example the following structure I think would be great:
again imagine we have example.com, api.example.com and sso-auth.example.com under admin user currently we have this (I exclude the folders admin_backups, Maildir, user_backups, imap or any other folder not related to the example):
What I suggest is to use this structure:
and a full structure would be something like this:
I'm sure some people with argue with me that the above will ad a complexity which for those who will argue with me is not needed but I insist that is needed, just think about the fact that internet is not like 5 - 10 years ago just a bunch of html/php pages with some css, js and images in it, things have changes, check around not only php frameworks use architectures like MVC, DDD, CQRS but also we have js mvc frameworks (check backbone etc) we have css frameworks like compass-style with a proper structure what I mean is that nowadays web applications follow some structures that are proven to be working and developers follow those structures to architect their projects better, developers are not related to server administration or stuff like that they won't do any vhost configurations or any extreme .htaccess files they will do what they know best and this is not server configuration
And to conclude one thing more (you can take is as extra feature) is to give the ability up-on domain or subdomain creation to specify custom document root in case we don't want public_html as a name but we need for example public, or web or front etc to be able to do so
My request is that subdomains should be isolated from the domains and not be just a folder under public_html folder.
A case of example, I create subdomain.example.com and I don't want it to be accessible from example.com/subdomain
A more realistic case as a web developer I build RIA apps where lot of times I need something like api.example.com sso-auth.example.com etc
if we say that 1 RIA app has the following structure:
Code:
root/
libraries/
src/
public_html/
Then if we say that we have the following domain / subdomains: example.com, api.example.com and sso-auth.example.com we will have this structure (I exclude folders like private_html public_ftp etc since they are not needed in this example):
Code:
example.com/
public_html/
api/
sso-auth/
With the above we will be able to access our main application from example.com domain, our API container from api.example.com and example.com/api and our sso authentication system from sso-auth.example.com and example.com/sso-auth
What we end up is double log and statistic records because of the way subdomains treated but the worst is that we end up with this structure:
Code:
example.com/
libraries/
src/
public_html/
api/
libraries/
src/
public_html/
sso-auth/
libraries/
src/
public_html/
So where is the problem with this structure? from security perspective folders like libraries and src should not be under public folder for any reason so having those folders under public folder is a great security risk. From architecture perspective the document root for any cases should be public_html so the document root for the domain / subdomains should be like this:
example.com -> example.com/public_html
api.example.com -> example.com/public_html/api/public_html
sso-auth.example.com -> example.com/public_html/sso-auth/public_html
The above is actually meaningless since even if subdomains will have their own document root they will be still accessible by their parent domain which is example.com
I could provide more cases in order to prove wrong the current subdomain treatment if you like.
For all the above I know there are ways to change for example customize vhosts, .htaccess files in order to deny example.com/subdomain type access and adding custom document root and etc but the case is to do those things automatically.
From what I though the best way to treat subdomains would be same as domains, for example the following structure I think would be great:
again imagine we have example.com, api.example.com and sso-auth.example.com under admin user currently we have this (I exclude the folders admin_backups, Maildir, user_backups, imap or any other folder not related to the example):
Code:
/home/admin/domains/example.com/public_html/
/home/admin/domains/example.com/public_html/api/
/home/admin/domains/example.com/public_html/sso-auth/
What I suggest is to use this structure:
Code:
/home/admin/domains/example.com/public_html/
/home/admin/subdomains/api/public_html/
/home/admin/subdomains/sso/public_html/
and a full structure would be something like this:
Code:
/home/admin/admin_backups/
/home/admin/domains/example.com/
/home/admin/domains/example.com/private_html
/home/admin/domains/example.com/public_ftp
/home/admin/domains/example.com/public_html
/home/admin/domains/example.com/logs
/home/admin/domains/example.com/stats
/home/admin/subdomains/api/private_html
/home/admin/subdomains/api/public_ftp
/home/admin/subdomains/api/public_html
/home/admin/subdomains/api/logs
/home/admin/subdomains/api/stats
/home/admin/subdomains/sso-auth/private_html
/home/admin/subdomains/sso-auth/public_ftp
/home/admin/subdomains/sso-auth/public_html
/home/admin/subdomains/sso-auth/logs
/home/admin/subdomains/sso-auth/stats
/home/admin/Maildir/
/home/admin/user_backups/
/home/admin/imap/
/home/admin/imap/example.com
/home/admin/imap/api.example.com
/home/admin/imap/sso-auth.example.com
/home/admin/public_html -> /home/admin/domains/example.com/public_html
I'm sure some people with argue with me that the above will ad a complexity which for those who will argue with me is not needed but I insist that is needed, just think about the fact that internet is not like 5 - 10 years ago just a bunch of html/php pages with some css, js and images in it, things have changes, check around not only php frameworks use architectures like MVC, DDD, CQRS but also we have js mvc frameworks (check backbone etc) we have css frameworks like compass-style with a proper structure what I mean is that nowadays web applications follow some structures that are proven to be working and developers follow those structures to architect their projects better, developers are not related to server administration or stuff like that they won't do any vhost configurations or any extreme .htaccess files they will do what they know best and this is not server configuration
And to conclude one thing more (you can take is as extra feature) is to give the ability up-on domain or subdomain creation to specify custom document root in case we don't want public_html as a name but we need for example public, or web or front etc to be able to do so
Last edited: