How can I create subdomains in PHP? I want every user that signs up on my site to instantly have their own subdomain.
EDIT
I have this working now. First I allowed wildcard subdomains in my server. I achieved that in JustHost by creating a subomain manually named *
and specifying a folder called subdomains as the document root for wildcard subdomains. I added this to my .htaccess
file in my subdomains folder:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.website\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.website\.com$
RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
RewriteRule ^(.*)$ /%1/$1 [QSA]
Finally, I created a folder for my subdomain and place the subdomains files.