Suppose domain is domain.name,
after a new user sign up,need to generate a new domain:user1.domain.name.
How to impleme开发者_开发问答nt it?
BTW,is there a limit for the number of sub domains?
I would simply use a wildcard to point all subdomains to a certain directory and have a front controller there that determines the used one from the URL - this is the easiest and safest solution from PHP.
EDIT Then you can obviously check whether that one should be existing (store them in a database or whatever) etc.
What you are asking for is known as Wildcard DNS record:
- http://en.wikipedia.org/wiki/Wildcard_DNS_record
Basic DNS/Apache setup:
- http://ma.tt/2003/10/wildcard-dns-and-sub-domains/
App-side logic (crappy code):
- http://sebastiano.ezion.cc/2008/03/08/wildcard-dns-and-php/
Subdomains can be retrieved with .htaccess (you need however wildcard mentioned earlier in this thread):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^user([0-9]{1,10}).domain.name$
RewriteRule ^.*$ index.php?subdomain=%1
精彩评论