If your website needs to add the information of two websites in one backend, then your frontend will have four modules, the main domain name, the mobile version of the main domain name, the secondary domain name, and the mobile version of the secondary domain name. You need to add the main domain name The modules of the secondary domain name and the secondary domain name are bound to different domain names respectively, and the routing of the primary domain name and the secondary domain name are exactly the same, you can refer to my routing configuration method below,
<?php //主域名的 路由定义 Route::rule('/', 'index/index'); Route::rule('category/:id/[:p]', 'content/lists');//导航分类 Route::rule('preview/:id/[:p]', 'content/preview');//后台预览 Route::rule('categorys/:ids/[:p]', 'content/lists');//新闻标签 Route::rule('view/:id', 'content/view');//资讯详情 Route::rule('views/:id', 'content/views');//网站地图 Route::rule('message', 'content/message');//在线留言 Route::rule('sitemap.xml', 'index/sitemap');//这是蜘蛛地图路由 //主域名的手机站 Route::domain('m.'.config ( 'setting.web_site_net' ), function () { // 动态注册域名的路由规则 Route::rule('/', 'wap/index/index'); Route::rule('entry/:id/[:p]', 'wap/content/lists'); //导航分类 Route::rule('entrys/:ids/[:p]', 'wap/content/lists');//新闻标签 Route::rule('detail/:id', 'wap/content/view');//资讯详情 Route::rule('messages', 'wap/content/message');//在线留言 })->bind('wap'); // 第二域名主域名 完整域名绑定到index_en模块 if(config ( 'setting.is_www' )){ $web_site_net_en= 'www.' . config ( 'setting.web_site_net_en' ); }else{ $web_site_net_en= config ( 'setting.web_site_net_en' ); } Route::domain($web_site_net_en, function () { // 动态注册域名的路由规则 Route::rule('/', 'index_en/index/index'); Route::rule('category/:id/[:p]', 'index_en/content/lists'); Route::rule('preview/:id/[:p]', 'index_en/content/preview'); Route::rule('categorys/:ids/[:p]', 'index_en/content/lists'); Route::rule('view/:id', 'index_en/content/view'); Route::rule('views/:id', 'index_en/content/views'); Route::rule('message', 'index_en/content/message'); Route::rule('sitemap.xml', 'index_en/index/sitemap'); })->bind('index_en'); //第二域名手机域名 Route::domain('m.'.config ( 'setting.web_site_net_en' ), function () { // 动态注册域名的路由规则 Route::rule('/', 'wap_en/index/index'); Route::rule('entry/:id/[:p]', 'wap_en/content/lists'); //导航分类 Route::rule('entrys/:ids/[:p]', 'wap_en/content/lists');//新闻标签 Route::rule('detail/:id', 'wap_en/content/view');//资讯详情 Route::rule('messages', 'wap_en/content/message');//在线留言 })->bind('wap_en'); // 全局变量 支持批量添加 Route::pattern([ 'name' => '\w+', 'id' => '\d+', ]);
Finally, , if it is developed locally with phpstudy and is in an apache environment, you need to configure four domain names in one domain name management. You can write the other three domain names together with spaces in the second domain name, and finally bind them in the host file. These four domain names can be localized
Recommended tutorial: "TP5"
The above is the detailed content of ThinkPHP5.1 domain name binding module. For more information, please follow other related articles on the PHP Chinese website!