Home  >  Article  >  PHP Framework  >  ThinkPHP5.1 domain name binding module

ThinkPHP5.1 domain name binding module

Guanhui
Guanhuiforward
2020-04-30 10:18:095284browse

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(&#39;/&#39;, &#39;index/index&#39;);
Route::rule(&#39;category/:id/[:p]&#39;, &#39;content/lists&#39;);//导航分类
Route::rule(&#39;preview/:id/[:p]&#39;, &#39;content/preview&#39;);//后台预览
Route::rule(&#39;categorys/:ids/[:p]&#39;, &#39;content/lists&#39;);//新闻标签
Route::rule(&#39;view/:id&#39;, &#39;content/view&#39;);//资讯详情
Route::rule(&#39;views/:id&#39;, &#39;content/views&#39;);//网站地图
Route::rule(&#39;message&#39;, &#39;content/message&#39;);//在线留言
Route::rule(&#39;sitemap.xml&#39;, &#39;index/sitemap&#39;);//这是蜘蛛地图路由
//主域名的手机站
Route::domain(&#39;m.&#39;.config ( &#39;setting.web_site_net&#39; ), function () {
    // 动态注册域名的路由规则
    Route::rule(&#39;/&#39;, &#39;wap/index/index&#39;);
    Route::rule(&#39;entry/:id/[:p]&#39;, &#39;wap/content/lists&#39;); //导航分类
    Route::rule(&#39;entrys/:ids/[:p]&#39;, &#39;wap/content/lists&#39;);//新闻标签
    Route::rule(&#39;detail/:id&#39;, &#39;wap/content/view&#39;);//资讯详情
    Route::rule(&#39;messages&#39;, &#39;wap/content/message&#39;);//在线留言
})->bind(&#39;wap&#39;);
// 第二域名主域名 完整域名绑定到index_en模块
if(config ( &#39;setting.is_www&#39; )){
    $web_site_net_en= &#39;www.&#39; . config ( &#39;setting.web_site_net_en&#39; );
}else{
    $web_site_net_en=  config ( &#39;setting.web_site_net_en&#39; );
}
Route::domain($web_site_net_en, function () {
    // 动态注册域名的路由规则
    Route::rule(&#39;/&#39;, &#39;index_en/index/index&#39;);
    Route::rule(&#39;category/:id/[:p]&#39;, &#39;index_en/content/lists&#39;);
    Route::rule(&#39;preview/:id/[:p]&#39;, &#39;index_en/content/preview&#39;);
    Route::rule(&#39;categorys/:ids/[:p]&#39;, &#39;index_en/content/lists&#39;);
    Route::rule(&#39;view/:id&#39;, &#39;index_en/content/view&#39;);
    Route::rule(&#39;views/:id&#39;, &#39;index_en/content/views&#39;);
    Route::rule(&#39;message&#39;, &#39;index_en/content/message&#39;);
    Route::rule(&#39;sitemap.xml&#39;, &#39;index_en/index/sitemap&#39;);
})->bind(&#39;index_en&#39;);
//第二域名手机域名
Route::domain(&#39;m.&#39;.config ( &#39;setting.web_site_net_en&#39; ), function () {
    // 动态注册域名的路由规则
    Route::rule(&#39;/&#39;, &#39;wap_en/index/index&#39;);
    Route::rule(&#39;entry/:id/[:p]&#39;, &#39;wap_en/content/lists&#39;); //导航分类
    Route::rule(&#39;entrys/:ids/[:p]&#39;, &#39;wap_en/content/lists&#39;);//新闻标签
    Route::rule(&#39;detail/:id&#39;, &#39;wap_en/content/view&#39;);//资讯详情
    Route::rule(&#39;messages&#39;, &#39;wap_en/content/message&#39;);//在线留言
})->bind(&#39;wap_en&#39;);
// 全局变量 支持批量添加
Route::pattern([
    &#39;name&#39; => &#39;\w+&#39;,
    &#39;id&#39;   => &#39;\d+&#39;,
]);

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete