TP5.1的路由功能真的是非常强大,同时学习难度也不小。
同一个入口,实现前台与后台分开访问。
路由配置如下:
// 域名绑定到index网站模块
Route::domain('mydomain.com, function () {
//首页
Route::rule('/','index/Index/index')->ext('html');
//产品列表
Route::rule('/products-list/<catid>/<c?>','index/Index/lists')
->pattern(['c' => '\w+', 'catid' => '\d+'])
->ext('html')
->name('product_lists');
//产品详情
Route::rule('/item/<id>/<i?>','index/Index/details')
->pattern(['i' => '\w+', 'id' => '\d+'])
->ext('html')
->name('product_details');
//产品搜索
Route::rule('/search/<q?>-<catid?>','index/Index/search','POST|GET')
->pattern(['q' => '\w+', 'catid' => '\d+'])
->ext('html')
->name('site_search');
//网站页面
Route::rule('/<p?>','index/Index/pages')
->pattern(['p' => '\w+'])
->ext('html')
->name('site_pages');
//不存在
Route::miss('index/Index/index');
}); 最佳答案