I want to create subdomains dynamically through a PHP script or something similar. I've seen lots of sites that create subdomains for individual users, or for new forum spaces. I'm just wondering how that works, and how I can implement it in my system.
Thanks for your help!
Take a look into wildcard subdomains. Once you have all of the "subdomains" going to the right place, you can use url rewriting and/or some other mixture of redirecting to create the effect of subdomains without having to constantly update a httpd.conf setup and/or DNS tables.
If you are using Apache on a Linux box, you can create new VirtualHosts for each subdomain. Here is a guide for Debian/Ubuntu which may also work for other distros.
Basically: each entry goes into its own file under /etc/apache2/sites-enabled. Whenever an entry is added/changed/removed, you run 'sudo /etc/init.d/apache2 reload' to update the virtual hosts / subdomains.
来源:https://stackoverflow.com/questions/1297681/creating-subdomains-dynamically-for-an-application