How to let PHP to create subdomain automatically for each user?

前端 未结 12 1011
暖寄归人
暖寄归人 2020-11-22 13:43

How do I create subdomain like http://user.mywebsite.com ? Do i have to access htaccess somehow? Is it actually simply possible to create it via pure php code or I need to u

12条回答
  •  忘了有多久
    2020-11-22 14:25

    This can be achieved in .htaccess provided your server is configured to allow wildcard subdomains. I achieved that in JustHost by creating a subomain manually named * and specifying a folder called subdomains as the document root for wildcard subdomains. Add this to your .htaccess file:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.website\.com$
    RewriteCond %{HTTP_HOST} ^(\w+)\.website\.com$
    RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
    RewriteRule ^(.*)$ /%1/$1 [QSA]
    

    Finally, create a folder for your subdomain and place the subdomains files.

提交回复
热议问题