我的路由有问题.我的默认控制器(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);
}
}
?>
解决方法:
刚刚遇到同样的问题,只需将.htaccess文件移动到工作目录的根目录即可
把它从应用程序文件夹中删除