I'm investigating the configuration of Name-based virtual hosts, under apache, for the provisioning of a main domain, and its sub-domain. I've found one example on the web that suggests a configuration as follows:
Listen 80
NameVirtualHost *
<VirtualHost *>
ServerName www.domain.com
DocumentRoot /home/httpd/htdocs/
</VirtualHost>
<VirtualHost *>
ServerName subdomain.domain.com
DocumentRoot /home/httpd/htdocs/subdomain/
</VirtualHost>
which makes sense until the DocumentRoot
directives. Am I correct in saying that it's less than wise to have one virtual hosts's document root, a descendant of another? Doesn't that configuration mean that the "subdomain" directory will server up content at both domains?
This example will work. However, the content at http://www.example.com/subdomain/ will be the same as http://subdomain.example.com/
What I would use is:
Sometimes it is advantageous to be able to access domain.com/subdomain until the dns for the new subdomain becomes active. This example configuration is the default with many control panels, and unless you have specific needs otherwise, it doesn't actually hurt anything.
You can always add a .htaccess mod_rewrite config that confirms that the http_host is subdomain.domain.com and if not, do a redirect, if you don't want users to be able to access in that fashion. (this is really your only choice if you are not the server administrator, and the control panel lays out your docroot in this fashion)