1.開啟apache的mod_rewrite模塊
- 去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符號
- 確保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>',
],
],
)
3.在與index.php文件同級目錄下(/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
- 注意:如果是Mac系統(tǒng),".htaccess"文件是無法創(chuàng)建的眉反,則要開啟顯示隱藏文件的功能:
defaults write com.apple.finder AppleShowAllFiles -bool true
再重啟電腦,真是蛋疼穆役,媽蛋
over~