N
N
Nikita Kolosov2014-04-09 13:25:43
Yii
Nikita Kolosov, 2014-04-09 13:25:43

How to implement subdomain routing in Yii?

The essence is as follows:
There are three modules:
backend
promo
mobile
The mobile module opens a specific site by the GET parameter "link"
I want to make this parameter (link) a subdomain, i.e., so that the link test.example.com opens example.com/mobile /default/index/link/test etc ( test.example.com/profile -> example.com/mobile/profile/index/link/test ), but backend and promo continued to work with standard yii/
At the moment, the following decision was made in the config:

'urlManager' => array(
   'urlFormat'      => 'path',
   'showScriptName' => false,
      'rules' => array(
    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', 
    'http://www.example.com' => '/',
    'http://<link:\w+>.example.com'                                        => 'mobile/default/index/',
    'http://<link:\w+>.example.com/<controller:\w+>/<action:\w+>/<id:\d+>' => 'mobile/<controller>/<action>',
    'http://<link:\w+>.example.com/<controller:\w+>/<action:\w+>'          => 'mobile/<controller>/<action>',
    'http://<link:\w+>.example.com/<controller:\w+>'                       => 'mobile/<controller>/index',
    'http://<link:\w+>.example.com/mobile/<controller:\w+>/<action:\w+>'   => 'mobile/<controller>/<action>',
')

However, in this solution, I'm not satisfied with the fact that when creating the address inside the mobile view module , the address is link.example.com/mobile/profile/index Is there any way to get rid of the word "mobile" in the links? Because now urls like link.example.com/profile/index also work, but are not generated. $this->createUrl('/mobile/profile/index')

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question