Rumah  >  Artikel  >  rangka kerja php  >  ThinkPHP5.1 域名绑定模块

ThinkPHP5.1 域名绑定模块

Guanhui
Guanhuike hadapan
2020-04-30 10:18:095271semak imbas

如果你的网站需要在一个后台里面加两个网站的资料,那么你的 前台就会有四个模块,主域名,主域名手机端,次域名,次域名手机端,需要把主域名和次域名的模块分别绑定到不同的域名上,并且主域名和次域名的路由完全一致的情况下,你可以参考下我下面这种配置路由方式,

<?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;,
]);

最后说下,如果是本地用的phpstudy 开发并且是apache环境的情况下,要在一个域名管理里面配置四个域名,可以在第二域名里面用空格把另外三个域名写一起,最后在host文件里面绑定这四个域名到本地即可

推荐教程:《TP5

Atas ialah kandungan terperinci ThinkPHP5.1 域名绑定模块. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Artikel ini dikembalikan pada:csdn.net. Jika ada pelanggaran, sila hubungi admin@php.cn Padam