How to implement a real-time subdomain in PHP?

Suppose domain is domain.name,

after registering a new user, you need to create a new domain: user1.domain.name.

How to implement it?

BTW, is there a limit to the number of subdomains?

+3
source share
3 answers

I would just use a wildcard to indicate all subdomains in a specific directory and have a front controller there that determines which one to use from the URL - this is the simplest and safest solution from PHP.

EDIT . Then you can obviously check if it should be existing (store them in a database, etc.), etc.

+6
source

Subdomains can be restored using .htaccess (you need, however, the wildcard mentioned earlier in this thread):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^user([0-9]{1,10}).domain.name$
RewriteRule ^.*$ index.php?subdomain=%1
+2
source

Source: https://habr.com/ru/post/1725828/


All Articles