简体   繁体   中英

How to group routes by domain in Laravel

Iam using Route::group to group route by domain

Route::group(['domain' => 'user.domain.local'], function() {

});

When I access user.domain.local/abc/, everything is ok.

But when I access www.user.doamin.local/abc/, Laravel throw HttpNotFoundException. I want to it same as when access user.domain.local/abc/

How do I fix it ? Thanks

Laravel Subdomain routing is the same as route prefixing , but it's scoped by subdomain instead of route prefix . In laravel, we can create features using Routing subdomain . Syntax essentially as follows:

Route::pattern('www', '(www|)');

Route::group(['domain' => '{www}.user.domain.local'], function() {

});

Laravel 5.3 - oldest

Route::pattern('user_subdomain', '(www.user|user)');

Route::group(['domain' => '{user_subdomain}.domain.local'], function ()
{
    ....
});

Laravel 5.4 - newest

Route::pattern('user_subdomain', '(www.user|user)');

Route::domain('{user_subdomain}.domain.local')->group(function ()
{
    ....
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM