Support the ongoing development of Laravel.io →
posted 10 years ago
Views
Last updated 2 years ago.
0

Is it possible I just need to update my first route to be grouped by domain as well?

I currently have it

Route::get('/', function() { return 'Hello from my main site!'; });

Route::group(array('domain' => 'crm.laravel.dev'), function() { Route::get('/', function() { return 'Hello from my subdomain!'; }); });

Would changing it to this help?

Route::group(array('domain' => 'laravel.dev'), function() { Route::get('/', function() { return 'Hello from my main site!'; }); });

Route::group(array('domain' => 'crm.laravel.dev'), function() { Route::get('/', function() { return 'Hello from my subdomain!'; }); });

Last updated 2 years ago.
0

Routes are ran one by one from top to bottom. The higher a route is the higher precedence it has.

A / route will match / on any domain (by default routes don't care about domain, only the path) therefore if you place your / route at the top it will match on crm.laravel.dev/ and not go any further. Place your subdomain specific route at the top:

// IF the domain is crm.laravel.dev
Route::group(array('domain' => 'crm.laravel.dev'), function() 
{ 
    // THEN match a GET request to /
    Route::get('/', function() 
    { 
        return 'Hello from my subdomain!'; 
    }); 
});

// match a GET request to / on ANY domain
Route::get('/', function() 
{ 
    return 'Hello from my main site!'; 
});
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mxalix258 mxalix258 Joined 20 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.