Problem with reading subdomain from $_GET

Hello,

Among others, I have this rule in my urlManager config:


'http://<site:\w+>.example.com/<controller:[\w-]+>/<action:[\w-]+>' => '<controller>/<action>'

So I am expecting site parameter to be set inside GET, because I can have multiple sites: en.example.com, ru.example.com

This is working until I make GET request like this: en.example.com?twitter=1

When I try to read site parameter, I get NULL:




$site = Yii::$app->request->get('site');

$site = (isset($site)) ? $site : 'not set';

Request like this is working as expected: en.example.com/site/index?twitter=1

I have set ‘defaultRoute’ => ‘site/index’,

So my problem is that I lose my site parameter, and I can not determine subdomain properly when I have request that do not specify at least controller in its URL ( it can always be site controller ).

Does anyone have any ides why I am losing site parameter from the GET ?

Why this works: en.example.com/site/index?twitter=1

And this doesn’t: en.example.com?twitter=1

For the rule to work as expected, the url need to have a part of string that matches ‘/<controller:[\w-]+>/<action:[\w-]+>’. Since ‘en.example.com?twitter=1’ doesn’t have it, it will be skipped by the rule.

Does this mean, that I can not handle this situation ?

I would try to add an additional rule for the ‘site/index’ route.




'http://<site:\w+>.example.com/<controller:[\w-]+>/<action:[\w-]+>' => '<controller>/<action>',

'http://<site:\w+>.example.com' => 'site/index'



Omg this worked. Thanks a lot, you saved me !