shoneZ89
(Nenad Z)
May 31, 2017, 12:07pm
1
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
softark
(Softark)
May 31, 2017, 1:30pm
2
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.
shoneZ89
(Nenad Z)
May 31, 2017, 2:25pm
3
softark:
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 ?
softark
(Softark)
May 31, 2017, 10:50pm
4
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'
shoneZ89
(Nenad Z)
June 1, 2017, 7:46am
5
softark:
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 !