1.开启apache-rewrite
LoadModule rewrite_module modules/mod_rewrite.so
相应路径的
Options FollowSymLinks
AllowOverride None
改为
Options FollowSymLinks
AllowOverride All
2.修改web.php
'urlManager' => [ 'enablePrettyUrl' => true,// Disable r= routes 'showScriptName' => false,// Disable index.php 'rules'=>[], ],
3.在入口文件同级目录下添加.htaccess文件
<IfModule mod_rewrite.c> # Options +FollowSymLinks # IndexIgnore */* RewriteEngine on # RewriteBase / #注意放在子目录要注释掉 # 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 </IfModule>