I am trying to create url like sub2.sub1.subdomain.domain.com. I am planning to use this to display different content.
my questions are...
1) Is it possible to create such multi level sub domains? - is this based on the hosting company?
2) Isn't sub2.sub1.subdomain a different subdomain rather than a sub domain of sub1?
3) Will all of these subdomains have their own doc roots?
4) How will I handle users coming with and without www.
Any other potential issues that might arise?
EDIT:- How does this affect the behaviour of cookies? Can I access a cookie set on subdomain.domain.com on sub1.subdomain.domain.com or sub2.sub1.subdomain.domain.com
Yes. You can have as many levels as you like in DNS.
Your host might limit what you are able to do.
That isn't a useful distinction.
Assuming that all the subdomains end up resolving to the same IP address (and they really don't have to):
Browsers will send the FQDN in the
Host
header. How the webserver handles that depends on the webserver.You can configure a separate Document Root for each — and you should (to avoid duplicate content penalties in search engines), unless you are going to do stuff to dynamically determine the content based on the FQDN.
However you like.
www
is only another subdomain without any special properties (other than convention). It is widely considered to be a good idea to pick either "with www" or "without www" as your canonical primary site and redirect the other one to it.You.can.go.as.deep.as.you.want.example.com.
1) This is mostly dependent on your DNS - usually, your hosting company manages this; also, if you have a wildcard 3rd-level domain (
*.example.com
), then any domain name underexample.com
will point to the same host. So, it is possible and works in 90% of the cases.2) It doesn't matter, really - it all depends on #3
3) If you configure them for different docroots, they will; else they won't.
4) Check the
Host:
header - there you'll see what the domain is (with PHP, this data would be in$_SERVER['HTTP_HOST']
), and you can implement some switching logic in your code.You can remove www by host panel or htaccess/web.config (by os default) bad rooting, however if you're using nginx, there's no htaccess file.
Subdomains have their own doc roots.