简体   繁体   中英

Laravel 4 - How to route subdomain to controller

I have a code work with laravel and Wildcard Domain. I like to using Subdomain Route for a controller and I have a route like this:

# Tester. URI : www.example.com/tester/{any}
Route::get('/tester/{any}', 'tester@Modules');

then i want to using Subdomain routing, so I change the route code like this:

#Subdomain route. URL : qwerty.example.com, it same as www.example.com/tester/qwerty
Route::group(array('domain' => '{parameter}.example.com'), function()
{
    Route::any('/tester/{parameter}', 'tester@Modules');
}

But didn't work. Can someone help me to resolve this problem? Thank you

Parameters in the domain like {parameter}.exam... will be merged with the ones from the route. This causes a naming conflict {parameter} and {parameter} . You must name the parameters differently:

Route::group(array('domain' => '{subdomain}.example.com'), function()
{
    Route::any('/tester/{parameter}', 'tester@Modules');
}

Note that the first argument passed to Modules() will be the subdomain and the second the actual route parameter.

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