How to create subdomain in Laravel dynamically?

假如想象 提交于 2019-12-03 09:36:37

问题


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

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>

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;
});

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

回答1:


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

then the

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

is now working.



来源:https://stackoverflow.com/questions/40804235/how-to-create-subdomain-in-laravel-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!