yii去掉index.php的方法:1、開啟apache的mod_rewrite模塊,并重啟apache;2、編輯項(xiàng)目中的/config/web.php文件;3、在與index.php文件同級(jí)目錄下添加【.htaccess】文件。
具體方法:
(推薦教程:php圖文教程)
1、開啟apache的mod_rewrite模塊
-
去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符號(hào)
-
確保DocumentRoot "/Library/WebServer/Documents"<Directory "…"></Directory>中有“AllowOverride All”
-
重啟apache,命令: sudo apachectl restart
2、在項(xiàng)目中的/config/web.php中添加代碼:
components'=>array( ... 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '<controller:w+>/<action:w+>'=>'<controller>/<action>', ], ], )
(視頻教程推薦:php視頻教程)
3、在與index.php文件同級(jí)目錄下(/web/)添加文件“.htaccess”,內(nèi)容如下:
Options +FollowSymLinks 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