在web 目录下新建文件 .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Otherwise forward it to index.php
RewriteRule . index.php
RewriteRule ^.git - [F,L]
</IfModule>
在config文件夹中的 main.php 或 web.php 中添加代码
'urlManager' => [
'enablePrettyUrl' => true, //启用路由
'enableStrictParsing' => false, // 启用 URL美化
'showScriptName' => false //禁用 index.php
],