Yii隱藏入口檔案index.php

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.