I’m rewriting a couple existing and related websites into the Yii framework. They’re for the same company and share the same databases, so I’ve setup each of the sites as a module. I needed each site’s existing domain name to point at a module – subdomains or subdirectories in the url would not be acceptable. Also, each of these sites has an administration site behind it. I could have set these up in Yii as a sub module, but elected to instead just create another module for them.
Take a look at the below code from the /protected/config/local.php file I created for my local environment
return CMap::mergeArray(
require (dirname(__FILE__) . '/main.php'),
array(
'components' => array(
'urlManager'=>array(
'rules' => array(
//front end of sites
'http://<module:\w+>.localhost/' => '<module>/default',
'http://<module:\w+>.localhost/<controller:\w+>' => '<module>/<controller>/',
'http://<module:\w+>.localhost/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
'http://<module:\w+>.localhost/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<controller>/<action>',
//admin subdomains for admin modules
'http://admin.<module:\w+>.localhost/' => '<module>admin/default',
'http://admin.<module:\w+>.localhost/<controller:\w+>' => '<module>admin/<controller>/',
'http://admin.<module:\w+>.localhost/<controller:\w+>/<action:\w+>' => '<module>admin/<controller>/<action>',
'http://admin.<module:\w+>.localhost/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>admin/<controller>/<action>',
),
),
)
)); |
return CMap::mergeArray(
require (dirname(__FILE__) . '/main.php'),
array(
'components' => array(
'urlManager'=>array(
'rules' => array(
//front end of sites
'http://<module:\w+>.localhost/' => '<module>/default',
'http://<module:\w+>.localhost/<controller:\w+>' => '<module>/<controller>/',
'http://<module:\w+>.localhost/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
'http://<module:\w+>.localhost/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<controller>/<action>',
//admin subdomains for admin modules
'http://admin.<module:\w+>.localhost/' => '<module>admin/default',
'http://admin.<module:\w+>.localhost/<controller:\w+>' => '<module>admin/<controller>/',
'http://admin.<module:\w+>.localhost/<controller:\w+>/<action:\w+>' => '<module>admin/<controller>/<action>',
'http://admin.<module:\w+>.localhost/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>admin/<controller>/<action>',
),
),
)
));
The trick to get the above working is to name your modules the same as your domain, so if your domain is abc.com, then your module name would be abc. To access your administration site, you’d create an abcadmin module and put admin.abc.localhost in the url. You can change the TLD extension for your needs.