代码点火器正确设置路由


CodeIgniter setting up routing properly

我正在尝试设置我的代码点火器路由以为管理面板制作身份验证表单,但路由不起作用。我是CodeIgniter的初学者,我想我错过了一些东西。

在我的服务器中,我将 CodeIgniter fiels放在根目录的文件夹中,因此可以像这样访问它:

/localhost/ci

在我的配置中.php我设置了我的基本 url 并删除索引页面以删除索引.php:

$config['base_url'] = 'http://localhost/ci/';
$config['index_page'] = '';

此外,我还编辑了.htaccess以删除索引.php就像CodeIgniter文档所说的那样,所以它看起来像这样:

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

现在,我的路由配置文件如下所示。我设置了默认页面和到身份验证控制器的路由:

$route['default_controller'] = 'auth';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['auth/login'] = "auth/login";

这是我的控制器:

类身份验证扩展CI_Controller {

function __construct() {
    parent::__construct();
    // load libraries
}
function index() {
    if (! $this->ion_auth->logged_in()) {
        // redirect them to the dashboard page
        redirect(base_url('auth/login'), 'refresh');
    } else {
        // show the dashboard page
        redirect(base_url('dashboard'), 'refresh');
    }
}
function login() {
    $this->load->view('login');
}

当我输入网络浏览器 http://localhost/ci/它会将我重定向到 http://localhost/ci/auth/login,但随后引发了 404 未找到错误 ir。我错过了什么?在这一点上我有点困惑,谢谢。

尝试将 .htaccess 从:

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

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