Laravel full URL routing

☆樱花仙子☆ 提交于 2019-12-08 03:47:55

问题


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 ..



来源:https://stackoverflow.com/questions/17132209/laravel-full-url-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!