材料准备一个干净的laravel,有两个Nginx配置文件,主要配置如下:server_name*.amor_laravel_test_1.amor;root/var/www/amor_laravel_test/public;indexindex.phpindex.htmlindex.htm;server_name*.amor_laravel_test.amor;root/var/www/amor_laravel_test/public;indexindex.phpindex.htmlindex.htm;将域名拆分成参数Route::domain('{account}.{webname}.{suffix}')->group(function(){Route::get('user/{id}',function($account,$webname,$suffix,$id){//可以在请求中接收split参数,可能的使用场景:在单独的路由中,需要根据不同的域名处理不同的需求dd($account,$webname,$suffix,$id);});});注意:如果账号不固定,可以配置NginxServerName为generic:*.example.com多个域名配置两个不同的域名如下:server_name*.amor_laravel_test.amor;server_name*.amor_laravel_test_1.amor;如何让Laravel匹配不同的域名?方法一:在route/web.php中直接使用domain来区分Route::domain('{account}.amor_laravel_test.amor')->group(function(){Route::get('user/{id}',function($account,$id){//dd($account,$id);});});Route::domain('{account}.amor_laravel_test_1.amor')->group(function(){Route::get('user/{id}',function($account,$id){//dd(111,$account,$id);});});方法二:通过设置RouteServiceProvider来区分添加方法:->group(base_path('routes/self.php'));}注册公共函数map(){$this->mapApiRoutes();$this->mapWebRoutes();$this->mapSelfRoutes();//}添加路由文件Route::get('/user',function($account){dd($account);});注意:必须设置所有的domain,如果只设置self,那么在同一个请求路径下,如果没有设置domain,会先匹配多个域名下route中Action的描述。首先,我们要知道Action决定了路由会绑定到哪个controller。另外需要注意的是路由中的Action属性,决定了辅助函数route()生成的url。假设,我们的路由配置如下:第一条路由Route::get('/',function(){if(\Illuminate\Support\Facades\Auth::check()){returnredirect('index');}else{returnredirect('login');}});第二条路线Route::get('/',function(){if(\Illuminate\Support\Facades\Auth::check()){returnredirect('index');}else{returnredirect('login');}});一模一样,都是调用内置的登录路由,controller也是一样的,我们看模板中的form表单
