如何在 Laravel 中动态创建子域?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40804235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create subdomain in Laravel dynamically?
提问by Vahn Marty
In my Windows/System32/drivers/etc/hosts, I have this:
在我的 Windows/System32/drivers/etc/ hosts 中,我有这个:
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:
在我的 xampp/apache/conf/extra/ httpd-vhost 中,我有这个:
<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:
现在,如果我要运行http://site.dev/project/public,它正在运行。我有这个路由命令:
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".
如果我打开http://sub.site.dev/startscript/public/,我会收到“无法访问此站点”的错误消息。
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
回答by Vahn Marty
I have solved it. I used Acyrlic DNS Proxy from this answer. Checkout the below link you will find the answer.
我已经解决了。我从这个答案中使用了 Acyrlic DNS 代理。看看下面的链接,你会找到答案。
then the
那么
Route::group(['domain' => '{account}.dns.dev'], function () {
Route::get('/', function ($account) {
return $account;
});
});
is now working.
现在正在工作。
回答by Parveen Chauhan
I am using laravel version above 5
我使用的是 5 以上的 laravel 版本
$appRoutes = function() {
Route::get('/',function(){
return view('welcome');
});
};
Route::group(['subdomain' => '{subdomain}.yoursitename.com'], $appRoutes );
Place this code in your route file.
But in my case, the laravel app was placed after the root so is used subdomain Route like this
将此代码放在您的路由文件中。
但在我的情况下,laravel 应用程序放置在根之后,因此使用子域 Route 像这样
$appRoutes = function() {
Route::get('/foldername/',function(){
return view('welcome');
});
};
Route::group(['subdomain' => '{subdomain}.yoursitename.com/foldername'], $appRoutes );