1.在config/app.php文件中开启动态路由
// 是否启用路由
'with_route' => true,
2.在route/app.php下配置规则
比如:
use think\facade\Route;
Route::get('think', function () {
return 'hello,ThinkPHP6!';
});
Route::get('hello/:name', 'index/hello');
3.在URL中使用路由模式访问
- 没有隐藏index.php的情况下URL:
http://localhost/index.php/think - 隐藏了index.php的情况下URL:
http://localhost/think
注意:即使使用Nginx隐藏了index.php,仍然可以使用index.php/think进行访问。