2014-08-28 75 views
0

我在Ubuntu 12.04.3上运行Apache 2.2.22(Windows 8.1上的Oracle VM)。 使用PHP phpinfo()函数我在加载模块下的apache2handler部分看到了mod_rewrite,所以启用了mod_rewrite。删除CodeIgniter 2.2.0上的index.php

我做了以下修改我的CI配置文件(application /配置/ 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

这工作!

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

所以,我们是否必须在根目录下创建'.htaccess'文件?正如我们知道'.htaccess'文件不存在于codeigniter 2.2的根目录中 – 2015-03-16 02:22:09

1

假设您的文件夹结构类似于/ var/www/html/testsite,并且您的url是localhost/testsite,那么上面的重写规则将在/ var/www/html而不是/ var/www/html/testsite。因此,在/ var/www/html/testsite的等效文件夹中,您可以尝试在位于/ var/www/html/testsite中的.htaccess文件中使用以下内容:.htaccess文件位于/ var/www/html/www/html等/测试网站/。所以你必须/var/www/html/testsite/.htaccess的代码...

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

我所做的是删除了前导/在最后一行的重写规则,所以它不是标题回到默认的文档根目录。

+0

感谢您的回复蒂姆,但没有奏效。我的CI是建立在我的虚拟机共享目录是这样的: 别名/测试网站/媒体/ sf_testsite/ <目录“/媒体/ sf_testsite /”> 选项-Indexes多视图 的AllowOverride无 订购允许,拒绝 从允许所有 – olen 2014-08-30 14:56:57