gpt4 book ai didi

php - Laravel 子域路由不起作用

转载 作者:可可西里 更新时间:2023-11-01 12:29:02 26 4
gpt4 key购买 nike

我正在尝试拥有一个管理子域 ( like this )

Route::group(['domain' => 'admin.localhost'], function () {
Route::get('/', function () {
return view('welcome');
});
});

但是admin.localhost就像localhost一样.我应该如何正确执行此操作?

我在 OSX 上使用 Laravel 5.1 和 MAMP

最佳答案

Laravel 以先到先得的方式处理路由,因此您需要将最不具体的路由放在路由文件的最后。这意味着您需要将您的路由组置于具有相同路径的任何其他路由之上。

例如,这将按预期工作:

Route::group(['domain' => 'admin.localhost'], function () {
Route::get('/', function () {
return "This will respond to requests for 'admin.localhost/'";
});
});

Route::get('/', function () {
return "This will respond to all other '/' requests.";
});

但是这个例子不会:

Route::get('/', function () {
return "This will respond to all '/' requests before the route group gets processed.";
});

Route::group(['domain' => 'admin.localhost'], function () {
Route::get('/', function () {
return "This will never be called";
});
});

关于php - Laravel 子域路由不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41703192/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com