Laravel 路由到子域

Laravel Routing To subdomain

我正在使用 Laravel 5.7。目前所有路线都经过Api.phpweb.phpwebsite.php。在该应用程序的实时版本中,有一个指向 website.php 的子域是 [anything].websiteaddress.com,而域 www.websiteaddress.com 指向 web.php。在本地环境中,如何使用 localhost:8000 访问子域。我试过使用 [anything].websiteaddress.com,它不起作用。访问子域的正确方法是什么?

1.Configure 在 Web 服务器中 httpd.conf 创建虚拟主机 ip 或命名你想要的

<VirtualHost *:80>

 ServerName website.com

 ServerAlias *.website.com

</VirtualHost>

2.route 配置卢克

Route::group(array('domain' => '{account}.website.com'), function() {

    Route::get('/', function($account, $id) {
        // ...
        return Redirect::to('https://www.website.com'.'/'.$account);
    });

});

您可以使用 http://lvh.me:8000.

lvh.me 是一项免费服务,可将所有子域自行解析为 localhost.

没有要安装的东西或 运行。如果您想测试 example 子域,您只需转到 http://example.lvh.me:8000 即可。

它甚至可以在没有子域的情况下工作。例如,如果您 运行 正在 localhost:8000 on your dev box, you could go to lvh.me:8000 加载一个应用程序。

您也可以尝试 http://vcap.me:8000 and http://localtest.me:8000 它们都解析为 127.0.0.1localhost