一、确保开启了服务器的rewrite模块,检查httpd.conf
将LoadModule rewrite_module modules/mod_rewrite.so 前面的 ‘#’去掉
二、在YII2.0的根目录下,添加.htaccess
提示,如果windows不允许创建该文件,可以借助编辑器创建即可。
粘贴如下代码:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
如果不能工作,尝试下面的代码:
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
没有问题的话,它应该是可以的!