I’m creating a website using MVC framework (Yii) and I need to dynamically create subdomains, i.e. 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 http://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 http://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 http://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!
You could include hostname into your routing rules array. For example, you could create rules
and check for
companyparameter in yourother/routeaction. Please note thathttp://is required for those rules to work. See CUrlManager documentation for more details.P.S. If controllers for
http://www.website.comandhttp://company.website.com/user/registerare completely different it could be better to set up two applications for those sites.