我的路由有问题。我的默认控制器 (mysite.com) 可以工作,但如果我尝试其他任何操作(例如 mysite.com/dashboard),它会转到基于服务器的 404,而不是 CodeIgniter。这非常令人困惑,因为目前我的 routes.php 文件中只有 2 条路径。以下是我的 routes.php 文件中未注释的部分:
$route['404_override'] = '';
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
我的控制器位于 /application/controllers/pages.php。
我不认为这是一个 .htaccess 问题(因为它可以访问默认控制器),但这是我的 .htaccess 文件:
RewriteEngine On
RewriteCond $1 !^(index\.php|styles|scripts|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
#<IfModule mod_gzip.c>
# mod_gzip_on Yes
# mod_gzip_dechunk Yes
# mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
# mod_gzip_item_include handler ^cgi-script$
# mod_gzip_item_include mime ^text/.*
# mod_gzip_item_include mime ^application/x-javascript.*
# mod_gzip_item_exclude mime ^image/.*
# mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
#</IfModule>
编辑
这是页面控制器:
<?php
class Pages extends CI_Controller {
public function __construct()
{
//Construct it's parent
parent::__construct();
//Check login
//$this->load->model('pages_model');
//$this->pages_model->getLoginStatus();
}
public function view($page = 'dashboard')
{
//If the file doesn't exist
if ( ! file_exists('/var/www/vhosts/mysite/httpdocs/library/application/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
//Load all necessary views
$this->load->view('templates/head', $data);
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
?>