【问题标题】:Laravel 5.* root path in subdomainLaravel 5.* 子域中的根路径
【发布时间】:2015-10-01 00:07:43
【问题描述】:

我有基本域路由和子域路由。例如,如果我请求subdomain.example.com/test,它将返回正确答案。但是如果我想请求subdomain.example.com,它将执行来自根域的代码。

Route::get('/', function() {
    // Main 
});

Route::get('/path', function() {
    // .. 
});

Route::group(['domain' => 'subdomain.example.com'], function()
{
    Route::get('/', function() {
        // How to request this part?
    });

     Route::get('/test', function() {
        // Works
    });
}

【问题讨论】:

  • 您是否尝试过更改它们的定义顺序?
  • @ceejayoz 嗯..我还没有考虑过,但是是的,它有效!谢谢!
  • 整洁,将其添加为答案。

标签: laravel laravel-5 laravel-routing


【解决方案1】:

更改顺序会有所帮助 - Laravel 保持路由有序,并逐个检查它们,因此通过将子域的路由移动到主路由上方,它们将首先被找到并使用,全局路由作为后备对于其他域。

Route::group(['domain' => 'subdomain.example.com'], function()
{
    Route::get('/', function() {
        // How to request this part?
    });

     Route::get('/test', function() {
        // Works
    });
}

Route::get('/', function() {
    // Main 
});

Route::get('/path', function() {
    // .. 
});

【讨论】:

    猜你喜欢
    • 2015-09-10
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    • 1970-01-01
    • 2015-11-17
    • 2015-08-11
    • 1970-01-01
    相关资源
    最近更新 更多