thinkphp 路由参数 域名 miss设置

路由的使用

在route/app.php文件里设置路由


use think\facade\Route;

// rule()
// 还有其他的快捷方式 Route::GET POST PUT DELETE PATCH HEAD OPTIONS ANY
// Route::rule('index/:id', 'Login/index', 'GET|POST')->https();
// Route::get('index/:id', function ($id) {
//     return 'hello,ThinkPHP6!' . $id;
// });

// 参数
// ext 设置路由的后缀 强制路由后缀设置  全局设置后缀 在config/route.php中设置
// Route::rule('index/:id', 'Login/index')->ext('html|shtml|xml');

// denyExt 禁止访问的后缀
// Route::rule('index/:id', 'Login/index')->denyExt('html|shtml|xml|jpg|png');

// https 设置路由的请求类型
// Route::rule('index/:id', 'Login/index', 'GET|POST'); // ->https()

// domain 检测当前域名是否匹配 完整域名或子域名都可以 不匹配不能访问
// Route::rule('index/:id', 'Login/index')->domain('www.tp.cn');

// options 集中设置参数
// Route::rule('index/:id', 'Login/index')->options([
//     'https' => true,
//     'domain' => 'www.tp.cn'
// ]);

// 每个域名下生效不同的路由
// Route::domain('www.tp.cn', function () {
//    Route::rule('index/:id', 'Login/index');
// });
// Route::domain('www.tp2.cn', function () {
//    Route::rule('index/:id', 'Login/index');
// });

// 404 miss路由 找不到地址跳转到404页面
Route::rule('index/:id', 'Login/index');
Route::miss(function () {
    return '404 Not Found';
});
//或者跳转到指定的页面 方法
Route::miss('Login/error');

posted on 2024-01-24 17:49  完美前端  阅读(205)  评论(0)    收藏  举报

导航