C
C
Carlos Rodriguez2015-01-12 20:09:23
Nginx
Carlos Rodriguez, 2015-01-12 20:09:23

Yii2. How to create a subdomain during registration?

nginx web server. It is necessary to implement the creation of a subdomain when registering a user (for example, the user Vasya specified the domain vasya during registration; as a result, his profile should be available at vasya.example.com).
Tell me how it's done and how to implement it correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Terminaft, 2015-01-12
@Terminaft

There is a router in Yii2, everything is fine (comment to the previous answer).
We put alias as suggested by xmoonlight (you can on a separate part of the application if you use the advanced template).
In the router ($config->components):

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                 // остальной конфиг роутера
                'http://<login:[\w\-]+>.example.com/<action:\w+>' => 'profile/<action>', // контроллер ProfileController должен существовать, и в нем надо бы реализовать behavior (или метод init) на проверку существования пользователя с таким логином
            ],
        ],

X
xmoonlight, 2015-01-12
@xmoonlight

DNS:
A *.domain.com
and a router at the entrance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question