【问题标题】:Why am I getting 404 errors in CodeIgniter?为什么我在 CodeIgniter 中收到 404 错误?
【发布时间】:2015-04-12 19:20:16
【问题描述】:

我不明白为什么我在 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]

我正在使用本地主机,其他应用程序中的所有其他控制器都运行良好。这是我第一次遇到这个问题。

【问题讨论】:

  • 文件名是否以大写开头?
  • @Joerg 实际上没有。我的控制器是 home.php 和 add.php。
  • 在 Codeigniter 3 中,控制器文件名应该以大写开头。试试看,希望对你有帮助。
  • 它不起作用,我实际上并没有使用最新版本的 CodeIgniter :/

标签: php codeigniter http-status-code-404 codeigniter-url


【解决方案1】:

如果没有控制器类,它应该显示 404 not found 错误。也可以试试以大写开头的控制器文件名。

参考这个link

【讨论】:

    猜你喜欢
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多