Thinkphp5 Route用法

域名路由:domain

1.application/router.php 文件位置,吧一下代码放进去就可以了

use thinkRoute;
Route::domain('app.tp5a.com','app');   // 1.绑定到模块app
#Route::domain('app.tp5a.com','app/category'); //2.绑定到控制器category
#Route::domain('app.tp5a.com','app/category/test');   //3.绑定到方法test
把域名app.tp5a.com  绑定到模块 app模块

注意:要先application/config.php 开启 域名部署(url_domain_deploy => true)

别名路由:alias

文件位置:application/route.php 

方法一:

use thinkRoute;
Route::alias('test','index/index/test');

当访问xxx.com  会跳转到index/index/test

访问地址:http://tp5a.com/index.php/test   等同于  http://tp5a.com/index.php/index/index/test

方法二:

return [
    '__pattern__' => [
        'name' => 'w+',
    ],
    '[hello]'     => [
        ':id'   => ['index/hello', ['method' => 'get'], ['id' => 'd+']],
        ':name' => ['index/hello', ['method' => 'post']],
    ],
    '__alias__' =>  [
        'h'  =>  'index/hello',
        'test'=> 'index/index/test'
    ],
    
];

路由绑定:get

代码

Route::get('test','index/index/test');

访问  http://tp5a.com/index/test  和    http://tp5a.com/index.php/test

注意:如果是伪静态状态下 要tp5a.com/模块/方法(一定要带模块名) 

原文地址:https://www.cnblogs.com/wesky/p/7112422.html