问题
I am using the old Yii (v1), and I need to assign a different domain to two controllers only.
So I have a bunch of controllers - HomeController.php, CategoryController.php, GuestbookController.php, ShopController.php, ProfileController.php, all of them works with a domain aaaaa.com, but I need that controllers ShopController.php and ProfileController.php would work only with domain bbbbb.com.
P.S. When user clicks "My Profile" link or "Shop" the domain changes to bbbbb.com, when user clicks "Home", "Categorys", "Guestbook" the domain changes to aaaaa.com And when user enters URL aaaaa.com it goes to "Home" (HomeController.php) (as it is now) and when he enters bbbbb.com it goes to "Shop" (ShopController.php)
Its all one page with one Navigation bar.
回答1:
So you want different parts of your application to be served from two different domains that are both virtual hosts on the same server pointing to the same application.
You can easily do that with Yii's rewrite rules because you can specify full host when defining them.
This is an example from my application that is used for both the "happyanalytics" tool as for the "happyseotools" blog:
'urlManager'=>array(
'urlFormat'=>'path',
'urlSuffix'=>'/',
'showScriptName'=>false,
'rules'=>array(
'http://'._HOST_HAPPYANALYTICS_.'/' => '/analytics/default/index',
'http://'._HOST_HAPPYANALYTICS_.'/tour/' => '/analytics/default/tour',
'http://'._HOST_HAPPYANALYTICS_.'/pricing/' => '/analytics/default/pricing',
'http://'._HOST_HAPPYANALYTICS_.'/support/' => '/analytics/default/support',
'http://'._HOST_HAPPYANALYTICS_.'/login/' => '/analytics/default/login',
'http://'._HOST_HAPPYANALYTICS_.'/forgot_password/' => '/analytics/default/forgot_password',
'http://'._HOST_HAPPYANALYTICS_.'/signup/' => '/analytics/default/register',
'http://'._HOST_HAPPYANALYTICS_.'/dashboard/' => '/analytics/dashboard/index',
'http://'._HOST_HAPPYANALYTICS_.'/dashboard/website/<id_website>/<action:(visits|keywords|pages|debug|realtime|configuration|trackingCode)>/' => '/analytics/dashboard/<action>',
'http://'._HOST_HAPPYANALYTICS_.'/dashboard/website/<id_website>/' => '/analytics/dashboard/website',
'http://'._HOST_HAPPYANALYTICS_.'/dashboard/<action>/*' => '/analytics/dashboard/<action>',
'http://'._HOST_HAPPYSEOTOOLS_.'/' => 'site/index',
'http://'._HOST_HAPPYSEOTOOLS_.'/about/' => 'site/about',
'http://'._HOST_HAPPYSEOTOOLS_.'/contact/' => 'site/contact',
'http://'._HOST_HAPPYSEOTOOLS_.'/smile.gif' => 'site/tracker',
'http://'._HOST_HAPPYSEOTOOLS_.'/subscription/*' => 'site/subscription',
'http://'._HOST_HAPPYSEOTOOLS_.'/blog/posts/<tag:.*?>/'=>'/blog/post/index',
'http://'._HOST_HAPPYSEOTOOLS_.'/blog/'=>'/blog/post/index',
'http://'._HOST_HAPPYSEOTOOLS_.'/blog/<slug>/'=>'/blog/post/view',
),
),
As you imagine I have previously defined the domains as constants to not have to repeat them all the time. Also there might be a cleaner solution but this one works :)
来源:https://stackoverflow.com/questions/28276773/assign-different-domain-for-two-controllers-only