Answer the question
In order to leave comments, you need to log in
How to handle different domain names in Yii2?
The question is do I need on Yii2 Advanced to accept any hosts from the list in the database.
I have the main site mainSite.com, I want to make it possible to access it from different hosts (which will first be created and recorded in the database). The dns host will have a record of my main site IP (mainSite.com)
When accessing mainSite.com, the site works as it worked.
When accessing newSite.com, we look in the database if there is such a domain, after which it opens my own mainSite.com (just change the logo, for example).
The hosting is configured so that it can accept and process requests from any domain.
Does anyone know how to do this correctly?
Answer the question
In order to leave comments, you need to log in
Throw methods into the component that would allow you to determine what kind of subdomain it is, what options it has, etc., then it was convenient to access it everywhere through $yii::app->myDomainsComponent. When initializing this component, subscribe to request events and if, for example, the domain is incorrect, then redirect the person or throw exceptions, if correct, then write down all the crap that will be needed further in controllers, views, models.
In config
'on beforeAction' => function($event){
//Ваша логика. дергаем базу и т.д. Можно признак домена в params записывать, например
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question