为什么我在CodeIgniter中出现404个错误


Why am I getting 404 errors in CodeIgniter?

我不明白为什么CodeIgniter中出现404个错误。

我的默认控制器工作得很好:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
    public function index()
    {
        $this->load->view('home');
    }
}

但我的另一个控制器不工作(当我试图访问它的URL时,我得到了404):

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Add extends CI_Controller {
    public function index()
    {
        $this->load->view('add');

    }
}

以下是其他一些有用的信息:

$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = '';
$route['default_controller'] = "home";
$route['404_override'] = '';

.htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

我在localhost上工作,其他应用程序中的所有其他控制器都能完美工作。这是我第一次遇到这个问题。

如果没有控制器类,它应该显示404未找到错误。也可以尝试控制器文件名以大写字母开头。

请参阅此链接