Laravel full URL routing

2019-06-05 20:01发布

问题:

How can I set my routes depending on the domain-name? I want to register some actions to diffenrent domain-names (not sub-domains).

Example of the functionality I need to replicate:

Route::any('www.domain1.com', 'Controler@Action1'); 
Route::any('www.domain2.com', 'Controler@Action2'); 

I can't use URL rewriting in .htaccess because I store domain->route maping in my database.

回答1:

i think you can do it like this

Route::group(array('domain'=>'www.domain1.com'), function(){
    Route::get('/',array('as'=>'domain1Home', 'uses'=>'Controller@Action1'));
});

Route::group(array('domain'=>'www.domain2.com'), function(){
    Route::get('/',array('as'=>'domain2Home', 'uses'=>'Controller@Action2'));
});

you can know more about that from http://laravel.com/docs/routing#sub-domain-routing its some how the same way of thinking ..