Problem with reading subdomain from $_GET


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

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

So I am expecting site parameter to be set inside GET, because I can have multiple sites:,

This is working until I make GET request like this:

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:

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:

And this doesn’t:

For the rule to work as expected, the url need to have a part of string that matches ‘/<controller:[\w-]+>/<action:[\w-]+>’. Since ‘’ 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+><controller:[\w-]+>/<action:[\w-]+>' => '<controller>/<action>',

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

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