无法从CodeIgniter URL中删除index.php

Jun*_*ire 7 .htaccess codeigniter codeigniter-2

我的目录结构是/ var/www/CI /,文件夹CI下有所有文件夹,即应用程序,系统.在CI下创建了一个.htaccess文件.

以下是.htacess中的代码.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

仍然localhost/CI/blog出现404错误.谁能指导这条规则错在哪里?

Has*_*nab 26

请尝试以下方法

首先,确保按以下方式设置配置文件.

$config['index_page'] = '';
Run Code Online (Sandbox Code Playgroud)

还要确保在httpd.conf文件中启用了mod_rewrite,然后使用以下代码覆盖位于项目根文件夹中的.htaccess文件,而不是在应用程序文件夹中.

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
Run Code Online (Sandbox Code Playgroud)