Ok, sorry but I’m a complete newbie in the world of Apache configurations.
Your suggestion, is it that I should look into ServerAlias? Would the idea be to alias www and non-www domains like this:
ServerAlias www.dynamicdomain.comdynamicdomain.com
so that they both point to the same path? Probably not since they already point to the same path, right?
Using the below I can handle www and non-www domains completely dynamic. I’ve tested this and it works:
VirtualDocumentRoot /var/www/%-2.0.%-1.0/htdocs
Just to get this straight, do you only have 1 sub-domain or an unknown amount, (probably supported by wilcard DNS) ?
If you have just the three: example.com, www.example.com and sub.example.com I would just create three virtual hosts and be done with. Configuring that dynamically is harder than just defining the vhosts, and vhosts are easier for Apache, too!
If however sub.example.com was an example and you can you have lots of different subdomains, all dynamic, I would create a vhost for the ones you know will never change (example.com and www.example.com) and
use mass virtual hosting (VirtualDocumentRoot) to serve all the subdomains, OR
use a default host that catches all uncaught request and let a script on that host handle the request
NameVirtualHost 1.1.1.1:80
<VirtualHost 1.1.1.1:80>
# VirtualHost for a known host
ServerName example.com
ServerAlias www.example.com sub.example.com sub2.example.com
DocumentRoot /var/www/example.com/httpdocs
</VirtualHost>
# Optional more VirtualHosts for known hosts here
<VirtualHost 1.1.1.1:80>
# And mass virtual hosting for all other hosts
ServerName sub3.example.com
VirtualDocumentRoot /var/www/example/%0/htdocs
</VirtualHost>
You should change it to fit your needs of course, but the principle works. Just tested it :)[/s]
Is there no other solution? I’ve read about hardlinks and I “dont like the feel of it”… I rather skip manually setting up hardlinks for all new domains that I add.
I thought this would be a rather common question with some clear solutions available. I mean subdomains are used quite often.
Thanks for any additional hints, ideas, solutions.