Dynamic creation of subdomains

前端 未结 2 1314
难免孤独
难免孤独 2020-12-28 11:10

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

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-28 11:38

    If I understand your question, the 'company' component of the URL is a variable company name. I'll continue my answer under that assumption.

    Another option would be to create a company module (I'll call it 'Companies' for now), and use the CUrlManager rules to route to that controller. E.g.

    array(
        'http://.website.com/user/register' => '/companies/user/register',
        'http://.website.com/<_c:\w+>/<_a:\w+>' => '/companies/<_c>/<_a>' // more generic option
    ),
    

    The 'company' string will be passed to the application as $_GET['company'] and you can use this parameter in your CompaniesModule.php file to load some company specific data.

    Please note that without some other rule to handle www.website.com requests (as per Grey Teardrop's answer) you will get errors on requests to that subdomain.

提交回复
热议问题