问题描述
限时送ChatGPT账号..我正在使用 MVC 框架 (Yii) 创建一个网站,我需要动态创建子域,即 http://company.website
I'm creating a website using MVC framework (Yii) and I need to dynamically create subdomains, i.e. http://company.website
因此,为了实现这一点,我添加了一个 DNS 通配符 (*.website).现在的问题是我的应用程序控制器对于 www.website 和 company.website 都是一样的.例如,我有一个带有 Register
操作(user/register
)的 User
控制器.现在,如果我去www.website/user/register,我可以注册,但如果我去company.website,我可以完全做同样的事情/用户/注册.这种行为对我所有的控制器都是一样的.
So, in order to achieve this I've added a DNS wildcard (*.website). Now the problem is that my application controllers are all the same for www.website and for company.website. For example, I have a User
controller with Register
action (user/register
). Now if I go to www.website/user/register I can register, but I can do exactly the same if I go to company.website/user/register. And this behaviour is the same for all my controllers.
我意识到一切正常,但是如何将 www.website 和 compnay.website 的控制器分开?我不希望用户从 subdomian url 访问注册/登录/其他控制器和操作.
I realize everything is working correctly, but how do I separate controllers for www.website and for compnay.website? I don't want users to access register/login/other controllers and actions from the subdomian url.
非常感谢任何建议!
谢谢!
推荐答案
您可以将主机名包含到路由规则数组中.例如,您可以创建规则
You could include hostname into your routing rules array. For example, you could create rules
array(
'http://www.website/user/register' => 'user/register',
'http://<company:\w+>.website/user/register' => 'other/route',
)
并检查 other/route
操作中的 company
参数.请注意,这些规则需要 http://
才能起作用.有关详细信息,请参阅 CUrlManager 文档.
and check for company
parameter in your other/route
action. Please note that http://
is required for those rules to work. See CUrlManager documentation for more details.
附言如果 http://www.website
和 http://company.website/user/register
的控制器完全不同,最好设置这些网站的两个应用程序.
P.S. If controllers for http://www.website
and http://company.website/user/register
are completely different it could be better to set up two applications for those sites.
这篇关于动态创建子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论