和朋友在作一個小網站,用到了CI框架,以前測試都是在windows上,隱藏index.php也相對比較簡單。但服務器是ubuntu系統,須要配置一下,根據網上看到的一些教程,結合本身電腦的特色,記錄步驟以下:php
1.服務器環境: ubuntu12.04 64位html
2.開啓mod_rewrite模塊:apache
(1)將 /etc/apache2/mods-available/rewrite.load 鏈接到 /etc/apache2/mods-enabled/rewrite.load 來打開 Mod_rewrite 模塊.ubuntu
sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
(2)修改 /etc/apache2/sites-enabled/000-default,將其中的:AllowOverride None 修改成:AllowOverride All,以下:windows
DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
重啓apache2:服務器
sudo service apache2 restart
3.在CI的根目錄下,即在system的同級目錄下,新建.htaccess文件:app
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php|index\.html|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
若是CI目錄不是在www的根目錄下,例如個人是:http://localhost/iter/index.php/,第四行須要改寫爲RewriteRule ^(.*)$ /iter/index.php/$1 [L]。框架
4.將CI中配置文件(system/application/config/config.php)中,將 $config['index_page'] = "index.php"; 中的index.php去掉。ide
//$config['index_page'] = "index.php"; $config['index_page'] = ""; 。
大功告成,小夥伴試試看!!!測試