和朋友在作一个小网站,用到了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'] = ""; 。
大功告成,小伙伴试试看!!!测试