tp5實現綁定子域名,并且根據子域名定義路由規則
發布時間:2020-10-03
TP5的路由規則,可以綁定子域名到對應的模塊,然后根據域名不同,使用不同的路由規則
use \think\Route;
Route::domain('admin','admin');//綁定admin子域名
Route::domain('en','en');//綁定en子域名
$request = \think\Request::instance();
$domain = $request->domain();
preg_match("#http://(.*?)\.#i", $domain, $match);
$domain=$match[1];
if($domain=='www'){
Route::get('news/:artid','index/article/index',['ext'=>'html']);
Route::get('newslist/:cateid','index/artlist/index',['ext'=>'html']);
}else if($domain=='en'){
Route::get('news/:artid','en/article/index',['ext'=>'html']);
Route::get('newslist/:cateid','en/artlist/index',['ext'=>'html']);
}else {
}