Laravel完整URL路由 [英] Laravel full URL routing

查看:429
本文介绍了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 ..

这篇关于Laravel完整URL路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆