一、確保開啓了服務器的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
沒有問題的話,它應該是可以的!