Creating subdomains dynamically for an application

旧街凉风 提交于 2019-12-21 06:40:06

问题


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!


回答1:


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.




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!