在config文件的配置文件里面,添加
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,//隐藏index.php
//'enableStrictParsing' => false,
'suffix' => '.html',//后缀,如果设置了此项,那么浏览器地址栏就必须带上.html后缀,否则会报404错误
'rules' => [
//'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
],
],
在项目文件夹下创建名为 .htaccess,内容
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php