標籤:yii 隱藏index.php
1、開啟apache的mod_rewrite模組
#去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符號#如果是ubuntu系統,系統預設是開啟rewrite的cd /etc/apache2/mods-enabled#查看是否有rewrite.load連結檔案,如果沒有則建立連結檔案cd /etc/apache2/mods-enabledln -s ../mods-available/rewrite.load rewrite.load//這一步未驗證
2、確保 <Directory "..."></Directory>中有“AllowOverride All”
下面是一個樣本,其他情況類似:
#現有一個工程project,需要配置虛擬機器主機文檔cd /etc/apache2/sites-availablesudo vi project#放入如下內容<VirtualHost *:80> ServerAdmin [email protected] ServerName baike.petshome.cn DocumentRoot /var/www/project <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/project> Options FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>#然後確保AllowOverride All即可
3、修改項目設定檔,在項目中的/protected/config/main.php中修改代碼
‘components‘=>array(
...
‘urlManager‘=>array(
‘urlFormat‘=>‘path‘,
‘showScriptName‘=>false,//注意false不要用引號括上
...
),
4、在與index.php檔案同級目錄下添加檔案".htaccess"
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
這樣便可隱藏index.php入口檔案了。
參考資料:http://www.yiiframework.com/forum/index.php/topic/1061-%e9%9a%90%e8%97%8findexphp%e7%9a%84%e6%ad%a5%e9%aa%a4/
本文出自 “迷失的月亮” 部落格,請務必保留此出處http://luecsc.blog.51cto.com/2219432/1436656