- 通过域名路由闭包的形式,限制域名
//二级域名开头部分限制,
Route::domain('news',function(){
Route::rule('details/:id','Address/details');
});
//设置完整域名限制
Route::domain('news.tp.com',function(){
Route::rule('details/:id','Address/details');
});
//支持多个二级域名开头部分,使用相同的路由规则
Route::domain(['news','blog','live'],function(){
Route::rule('details/:id','Address/details');
});
//作为方法,进行二级域名开头部分检测,或完整域名检测
Route::rule('details/:id','Address/details')->domain('news');
Route::rule('details/:id','Address/details')->domain('news.abc.com');
- 跨域请求
当不同域名进行跨域请求的时候,由于浏览器的安全限制,会被拦截。为了解除这个限制,我们通过路由allowCrossDomain() 来实现;
Route::rule('details/:id','Address/details')->ext('html')->allowCrossDomain();
实现跨域请求比没有实现的 header 头文件多了几条开头为Access 信息
限制跨域请求的域名,则可以增加一条参数
Route::rule('col/:id','Collect/red')
->allowCrossDomain([
'Access-Control-Allow-Origin' => 'http://news.abc.com:8080'
]);