I am having problems with my routing. My default controller (mysite.com) will work, but if I try something else (like mysite.com/dashboard), it will go to 404 server, not CodeIgniter. This is very confusing since at the moment I have only 2 paths in the routes.php file. Below are the sections without comment in the routes.php file:
$route['404_override'] = '';
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
My controller is located in /application/controllers/pages.php.
I do not think this is a .htaccess problem (since it can get to the controller by default), but here is my .htaccess file:
RewriteEngine On
RewriteCond $1 !^(index\.php|styles|scripts|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
Edit
Here is the page controller:
<?php
class Pages extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function view($page = 'dashboard')
{
if ( ! file_exists('/var/www/vhosts/mysite/httpdocs/library/application/views/pages/'.$page.'.php'))
{
show_404();
}
$data['title'] = ucfirst($page);
$this->load->view('templates/head', $data);
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
?>
source
share