如何在Laravel中动态创建子域? [英] How to create subdomain in Laravel dynamically?

查看:115
本文介绍了如何在Laravel中动态创建子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows/System32/drivers/etc/主机中,我有以下内容:

In my Windows/System32/drivers/etc/hosts, I have this:

127.0.0.1   localhost
127.0.0.1   site.dev
127.0.0.1   *.site.dev

在我的xampp/apache/conf/extra/ httpd-vhost 中,我有以下内容:

In my xampp/apache/conf/extra/httpd-vhost, I have this:

<VirtualHost site.dev>  
  DocumentRoot "C:/xampp_7/htdocs/"
  <Directory "C:/xampp_7/htdocs/">
  </Directory>
</VirtualHost>
<VirtualHost *.site.dev>  
  DocumentRoot "C:/xampp_7/htdocs/"
  <Directory "C:/xampp_7/htdocs/">
  </Directory>
</VirtualHost>

现在,如果我要运行 http://site.dev/project/public ,工作中.我有以下路线命令:

Now if I am going to run http://site.dev/project/public, It is working. I have this route command:

Route::group(['domain' => '{subdomain}.site.dev'], function($subdomain) {
    return $subdomain;
});

如果我打开 http://sub.site.dev/startscript/public/ ,出现错误无法访问此站点".

If I open http://sub.site.dev/startscript/public/ , I get an error of "This site can’t be reached".

该程序的功能是它可以创建子目录.例如,我有一个商业网站.我可以这样访问/创建.

The function of the program is that it can create subdirectories. Example, I have a business website. I can access/create like this.

inventory.mybusiness.com
sales.mybusiness.com
ad.mybusiness.com

推荐答案

我已经解决了.我从此答案中使用了Acyrlic DNS代理.查看下面的链接,您将找到答案.

I have solved it. I used Acyrlic DNS Proxy from this answer. Checkout the below link you will find the answer.

https://laracasts.com/discuss/channels/general-discussion/dynamic-sub-domain-creation-on-new-user-registration-in-laravel-5-and-wampserver

然后

Route::group(['domain' => '{account}.dns.dev'], function () {
    Route::get('/', function ($account) {
        return $account;
    });
});

现在正在工作.

这篇关于如何在Laravel中动态创建子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆