ThinkPhp5绑定路由的一些小心得,子域名这样绑定路由模块也能够做到全绿

最近的捣鼓ThinkPhp5,然后想使得不同的模块绑定到不同的子域名上,发现TP5有个域名路由,然后在绑定的过程中发生了一些有趣的问题
(当然,绑定域名路由的前提当然是要把相应的域名解析并绑定该服务器,这是最基础的知识)

路由绑定原文教程

可以在应用的公共文件或者配置文件中动态注册域名部署规则,例如:
// blog子域名绑定到blog模块
Route::domain('blog','blog');
// 完整域名绑定到admin模块
Route::domain('admin.thinkphp.cn','admin');
// IP绑定到admin模块
Route::domain('114.23.4.5','admin');

补充说明
但是你在应用到公共文件application/common.php时,记得首先要引入

use think\Route;

绑定例子说明

假设我的域名是XXX.CN,我把想把admin.xxx.cn绑定admin模块,d绑定到device模块,xxx.cn直接绑到Index模块。

use think\Route;
Route::domain('xxx.cn','index');
Route::domain('admin','admin');
Route::domain('d','device');
return [
    '/:id$' => ['device/index/index', ['method' => 'get', 'ext' => '', 'domain'=>'d.xxx.cn']],
];

如果只是希望把某个子域名绑定到某个模块,只要在application/common.php公共文件这样简单配置即可

use think\Route;
Route::domain('子域名','绑定的模块名,注意只能小写');

子域名绑定路由模块绿锁

实际上就是通过开两个网站,分别绑定域名,但是网站目录是一样的(同一空间),上传对应的域名证书,达到绑定路由模块的子域名也能够绿锁的效果
首先是得申请一个免费的子域名的SSL,一般在阿里云购买的域名是可以直接申请免费的绿锁的
这里以宝塔为例,首先建立一个子域名的网站,绑定该子域名(相应的域名解析这里不多说)
第二步,在application/common.php公共文件配置路由绑定,上述教程有言
第三步,修改你该子域网站的网站目录与TP5路径一样(实绑定TP5同空间,非绑定模块目录路径)
第四步,在宝塔SSL上传该子域的证书文件,并开启强制HTTPS

Tags:路由绑定Thinkphp5php绿锁SSL
上一篇
打赏
下一篇

添加新评论

已有 24 条评论

 canadian mail order pharmacies to usa 昨天 19:56 • |

online pharmacies canada
http://canadiantrustmedpharmacy.com/
canadian pharmacy

 online pharmacy canada 昨天 18:09 • |

canadian online pharmacies
http://canadianpharmacypreshd.com/
prescription drugs without prior prescription

 http //www.reliablemedpharmacy.com/ 昨天 15:54 • |

online pharmacy
http://canadianpharmacybestmeds.com/
prescription meds without the prescription

 safe canadian online pharmacies 昨天 13:54 • |

prescription meds without the prescription
http://canadianonlinepharmacyph.com/
best canadian mail order pharmacies

 canadian pharmacies shipping to usa 昨天 12:03 • |

canadian online pharmacies
http://canadianonlinepharmacymrx.com/
prescription meds without the prescription

 canadian online pharmacies 昨天 10:27 • |

online drugstore
http://canadianonlinepharmacyelite.com/
online pharmacy

 canada drugs no prescription needed 昨天 08:58 • |

most reliable canadian pharmacies
http://canadianpharmaciesunlimited.com/
pharcharmy online no precipitation

 canadian online pharmacy 昨天 07:37 • |

canadian pharmacy
http://canadianpharmaciesshippingbsl.com/
best 10 online pharmacies

 canadian pharmacies 昨天 06:30 • |

international pharmacies that ship to the usa
http://canadianpharmaciesrxbest.com/
prescription drugs online without

 canadian pharmary without prescription 昨天 05:25 • |

canadian pharmacies
http://canadianpharmaciesprofmeds.com/
canada pharmacies online prescriptions

 MichaelZen 昨天 04:30 • |

Полисорб или Энтеросгель — что лучше для детей и взрослых: сравнение препаратов, состав, цена, показания и противопоказания, побочные эффекты
что лучше полисорб или энтеросгель отзывы врачей

 legitimate canadian mail order pharmacies 昨天 04:18 • |

canadian pharmacies top best
http://canadianpharmaciesoffer.com/
pharmacy without dr prescriptions

 legitimate online pharmacies 昨天 03:12 • |

pharcharmy online no precipitation
http://canadianpharmaciesnorth.com/
canada drugs no prescription needed

 legitimate canadian mail order pharmacies 昨天 02:08 • |

most reliable canadian pharmacies
http://canadianpharmacieslink.com/
online pharmacy canada

 canadian pharcharmy online 昨天 01:10 • |

canadian pharmacies
http://canadianpharmaciesgen.com/
canadian pharcharmy online

 mail order prescriptions from canada 1 天前 • |

legitimate canadian pharmacies
http://canadianonlinepharmacysl.com/
top 10 mail order pharmacies

 safe canadian online pharmacies 1 天前 • |

rx online no prior prescription
http://canadianonlinepharmacyoffer.com/
mexican pharmacies shipping to usa

 legitimate online pharmacies 1 天前 • |

safe canadian online pharmacies
http://canadianonlinepharmacyneo.com/
most reliable canadian pharmacies

 best 10 online pharmacies 1 天前 • |

approved canadian online pharmacies
http://canadianonlinepharmacyhd.com/
online pharmacy no prescription

 online pharmacy 1 天前 • |

canada pharmacies online prescriptions
http://canadianonlinepharmacycl.com/
canadian online pharmacies