在实际上线时候肯定要自定义规则好利于SEO或者浏览,以及精简URL的长度等等。
我们就需要设置URL的规则了,YII2配置就不多说了。'urlManager' => [
'enablePrettyUrl' => true, //路由的路径化
'showScriptName' => false,
'suffix' => '.html', //后缀
'rules' => [
// 为路由指定了一个别名,以 index的形式来表示 site/index 路由
'index' => 'site/index',
'webdir' => 'site/webdir', //网站目录首页
'webdir/' => 'site/webdir-list', //网站目录列表
'article' => 'site/article', //网站文章列表
'articleinfo/' => 'site/articleinfo', //网站文章详情
'web/' => 'site/web', //查看网站详情
// id 是命名参数,site/web?id=100
// 需要将 Web Server 配置成可以接收 *.xxx.com 域名的请求
//'http://.xxxx.com//profile' => 'user/profile',
],
],