动态创建子域

编程入门 行业动态 更新时间:2024-10-27 08:34:58
本文介绍了动态创建子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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.websitehttp://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:关键词]

本文发布于:2023-04-23 19:15:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047540.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!