[英]Laravel subdomain routing is not working
我正在嘗試擁有一個管理子域名( 像這樣 )
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";
});
});
Laravel的例子......
Route::group(['domain' => '{account}.myapp.com'], function () {
Route::get('user/{id}', function ($account, $id) {
//
});
});
你的代碼
Route::group(['domain' => 'admin.localhost'], function () {
Route::get('/', function () {
return view('welcome');
});
});
如果您查看laravel示例,它會在路徑中獲取參數$account
,這樣我們就可以根據此變量進行路由。 然后可以將其應用於組或其中的任何路徑。
也就是說,如果它不是由您的數據庫驅動的東西,而您只是希望它與admin子域,我個人會這樣做作為nginx配置。
如果你想在本地測試nginx(更簡單),我個人建議用docker進行開發。
希望這能回答你的問題,如果不是讓我知道並生病,試着為你回答。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.