Jos*_* T. 5 wildcard-subdomain yii
我正在使用MVC框架(Yii)创建一个网站,我需要动态创建子域名,即http://company.website.com
So, in order to achieve this I've added a DNS wildcard (*.website.com). Now the problem is that my application controllers are all the same for www.website.com and for company.website.com. For example, I have a User controller with Register action (user/register). Now if I go to www.website.com/user/register I can register, but I can do exactly the same if I go to company.website.com/user/register. And this behaviour is the same for all my controllers.
I realize everything is working correctly, but how do I separate controllers for www.website.com and for compnay.website.com? I don't want users to access register/login/other controllers and actions from the subdomian url.
Any suggestions are greatly appreciated!
Thank you!
小智 4
您可以将主机名包含到路由规则数组中。例如,您可以创建规则
array(
'http://www.website.com/user/register' => 'user/register',
'http://<company:\w+>.website.com/user/register' => 'other/route',
)
Run Code Online (Sandbox Code Playgroud)
并检查company您的操作中的参数other/route。请注意,这http://是这些规则发挥作用所必需的。有关更多详细信息,请参阅CUrlManager文档。
http://www.website.comPS 如果和 的控制器http://company.website.com/user/register完全不同,最好为这些站点设置两个应用程序。