删除CodeIgniter 2.2.0上的index.php

时间:2014-08-28 16:58:29

标签: .htaccess mod-rewrite codeigniter-2

我在Ubuntu 12.04.3上运行Apache 2.2.22(Windows 8.1上的Oracle VM)。 使用PHP phpinfo()函数我在加载模块下的apache2handler部分看到mod_rewrite,因此启用了mod_rewrite。

我对CI配置文件(application / config / config.php)进行了以下更改,

$config['index_page'] = 'index.php'; to: $config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; to: $config['uri_protocol']   = 'PATH_INFO';

我尝试了很多版本(位于CI根目录中的.htaccess文件):

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

但尚未开始工作。 我还缺少什么?

2 个答案:

答案 0 :(得分:2)

这很有用!

RewriteEngine On
RewriteBase /testsite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

答案 1 :(得分:1)

假设您的文件夹结构类似于... / var / www / html / testsite,并且您的url是localhost / testsite,那么上面的重写规则将在/ var / www中查找index.php / html而不是/ var / www / html / testsite。 (/ var / www / html将是默认文档根目录。)

因此,在/ var / www / html / testsite的等效文件夹中,您可以尝试在/ var / www / html / testsite /中的.htaccess文件中使用以下内容。所以你有/var/www/html/testsite/.htaccess代码......

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

我所做的就是删除了最后一行中的前导/重写规则,因此它不会返回默认文档根目录。