Laravel完整URL路由

问题描述:

如何根据域名设置路由?我想注册一些操作来区分不同的域名(而不是子域).

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'); 

我无法在.htaccess中使用URL重写,因为我将域->路由映射存储在数据库中.

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

我认为您可以这样做

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'));
});

您可以从 http://laravel.com/docs/routing了解更多#sub-domain-routing 的思维方式相同..

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