在 laravel 上实施通配符 DNS

Implements wild card dns on laravel

经过数小时的研究以找到正确的关键字以实现在 laravel 上使用通配符 dns 的简单方法。

我在这里使用 windows 10 和 laragon。

这是我在laravel路由

中尝试实现的代码
Route::group(['domain' => '{account}.tindahan.local'], function() {
  Route::get('/page-one', function () {
    return view('welcome0');
  });
  Route::get('/page-two', function () {
    return view('welcome1');
  });
});

根据我阅读的文章,您需要在 vhost 上设置类似 *.domian.com 的内容,我在 laragon

中自动设置了它
<VirtualHost *:80> 
    DocumentRoot "C:/laragon/www/tindahan/public/"
    ServerName tindahan.local
    ServerAlias *.tindahan.local
    <Directory "C:/laragon/www/tindahan/public/">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

但是当我尝试在 Chrome 浏览器上访问 page-one.tindahan.local 时,我收到了这条消息

This site can’t be reached

我不知道我在做什么缺少什么。第一次做这样的事情,基本上没什么想法。

你能告诉我正确的实现方法吗?

您当然应该将条目添加到您的主机文件中(在 windows 通常 C:\Windows\System32\drivers\etc\hosts)。例如你应该有:

127.0.0.1 tindahan.local

为主域,但您还应该添加其他子域,例如:

127.0.0.1 page-one.tindahan.local
127.0.0.1 page-two.tindahan.local

等等