title: Why do all my pages go to the same controller in CodeIgniter?
body: <p>When I load up my homepage, it works perfectly. The custom helper I made for the CSS and JS files is working and it loads through the correct controller/view. </p>
  
  <p>Every other page, however, loads from a the wrong controller (the News Controller). And the controller isn't using the custom helper for whatever reason, so there's no style on the page.</p>
  
  <p>Here's what I have in my routes.php and each of my controllers:</p>
  
  <p>route.php</p>
  
  <pre><code>$route['translate_uri_dashes'] = FALSE;
  
  $route['news'] = 'news/index/1';
  $route['news/create'] = 'news/create';
  $route['news/view'] = 'news/index/1';
  $route['news/view/(:any)'] = 'news/view/$1';
  $route['news/(:any)'] = 'news/index/$1';
  
  $route['logout'] = 'login/logout';
  $route['register'] = 'login/register';
  $route['confirm/(:any)/(:any)'] = 'login/confirm/$1/$2';
  
  $route['default_controller'] = 'index';
  $route['404_override'] = 'error';
  </code></pre>
  
  <p>Index Controller</p>
  
  <pre><code>&lt;?php
  
  class Index extends CI_Controller {
      public function __construct() {
          parent::__construct();
      }
  
      public function index() {
          $this-&gt;load-&gt;library('session');
  
          $data['page'] = 'Home';
          $data['section'] = 'None';
  
          if (isset($_SESSION['id'])) {
              $data['user'] = $this-&gt;user_model-&gt;get_user($_SESSION['id']);
          }
  
          $this-&gt;load-&gt;view('layout/header', $data);
          $this-&gt;load-&gt;view('layout/breadcrumb', $data);
          $this-&gt;load-&gt;view('layout/body');
          $this-&gt;load-&gt;view('index');
          $this-&gt;load-&gt;view('layout/close');
          $this-&gt;load-&gt;view('layout/footer');
      }
  } 
  </code></pre>
  
  <p>News Controller</p>
  
  <pre><code>&lt;?php
  
  class News extends CI_Controller {
      public function __construct() {
          parent::__construct();
          $this-&gt;load-&gt;model('news_model');
          $this-&gt;load-&gt;library('session');
      }
  
      public function index($page) {
          $data['page'] = 'News';
          $data['section'] = 'None';
  
          if (isset($_SESSION['id'])) {
              $data['user'] = $this-&gt;user_model-&gt;get_user($_SESSION['id']);
          }
  
          $data['news'] = $this-&gt;news_model-&gt;get_news(NULL, $page);
          $data['pageNo'] = $page;
          $data['entries'] = $this-&gt;news_model-&gt;get_total();
  
          $this-&gt;load-&gt;view('layout/header', $data);
          $this-&gt;load-&gt;view('layout/breadcrumb', $data);
          $this-&gt;load-&gt;view('layout/body');
          $this-&gt;load-&gt;view('news/index', $data);
          $this-&gt;load-&gt;view('layout/close');
          $this-&gt;load-&gt;view('layout/footer');
      }
  
      public function view($id) {
          $data['page'] = 'News';
  
          if (isset($_SESSION['id'])) {
              $data['user'] = $this-&gt;user_model-&gt;get_user($_SESSION['id']);
          }
  
          $data['news'] = $this-&gt;news_model-&gt;get_news($id);
  
          $data['section'] = $data['news']['title'];
  
          $data['prev'] = $this-&gt;news_model-&gt;get_prev($data['news']['pubDate']);
          $data['next'] = $this-&gt;news_model-&gt;get_next($data['news']['pubDate']);
  
          $data['pub'] = $this-&gt;user_model-&gt;get_user($data['news']['publisher']);
  
          $this-&gt;load-&gt;view('layout/header', $data);
          $this-&gt;load-&gt;view('layout/breadcrumb', $data);
          $this-&gt;load-&gt;view('layout/body');
          $this-&gt;load-&gt;view('news/view', $data);
          $this-&gt;load-&gt;view('layout/close');
          $this-&gt;load-&gt;view('layout/footer');
      }
  
      public function create() {
          $this-&gt;news_model-&gt;set_news();
          $this-&gt;session-&gt;set_userdata('created', 1);
          redirect('news');
      }
  } 
  </code></pre>
  
  <p>Login Controller</p>
  
  <pre><code>&lt;?php
  
  class Login extends CI_Controller {
      public function __construct() {
          parent::__construct();
          $this-&gt;load-&gt;library('session');
      }
  
      public function index() {
          $this-&gt;load-&gt;helper('form');
          $this-&gt;load-&gt;library('form_validation');
  
          $data['page'] = 'Login';
          $data['section'] = 'None';
  
          if (isset($_SESSION['id'])) {
              redirect('/');
          } else {
              $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'required', array('required' =&gt; 'You must provide a %s.'));
              $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required', array('required' =&gt; 'You must provide a %s.'));
  
              if ($this-&gt;form_validation-&gt;run() !== FALSE) {
                  $user = $this-&gt;user_model-&gt;login();
                  if ($user) {
                      $this-&gt;session-&gt;set_userdata('id', $user['id']);
                      redirect('/');
                  } else {
                      $this-&gt;session-&gt;set_userdata('loginerr', 1);
                  }
              }
  
              $this-&gt;load-&gt;view('layout/header', $data);
              $this-&gt;load-&gt;view('layout/breadcrumb', $data);
              $this-&gt;load-&gt;view('layout/body');
              $this-&gt;load-&gt;view('login');
              $this-&gt;load-&gt;view('layout/close');
              $this-&gt;load-&gt;view('layout/footer');
          }
      }
  
      public function logout() {
          $this-&gt;session-&gt;sess_destroy();
          redirect('/');
      }
  
      public function register() {
          $this-&gt;load-&gt;helper('form');
          $this-&gt;load-&gt;library('form_validation');
  
          $data['page'] = 'Register';
          $data['section'] = 'None';
  
          if (isset($_SESSION['id'])) {
              redirect('/');
          } else {
              $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'required', array('required' =&gt; 'You must provide a %s.'));
              $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required', array('required' =&gt; 'You must provide a %s.'));
              $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required', array('required' =&gt; 'You must provide a %s.'));
              $this-&gt;form_validation-&gt;set_rules('confpass', 'Confirm Password', 'required', array('required' =&gt; 'You must provide a %s.'));
  
              if ($this-&gt;form_validation-&gt;run() !== FALSE) {
                  $this-&gt;user_model-&gt;register();
  
                  if (isset($_SESSION['regerror'])) {
                      if ($_SESSION['regerror'] == 1) {
                          $data['error'] = 'Username is already in use.';
                      } else if ($_SESSION['regerror'] == 2) {
                          $data['error'] = 'Email Address is already in use.';
                      } else if ($_SESSION['regerror'] == 3) {
                          $data['error'] = 'Passwords do not match';
                      } else {
                          $data['error'] = 'This IP Address has been banned for the following reason: ' . $_SESSION['regerror'];
                      }
                      unset($_SESSION['regerror']);
                  } else if (isset($_SESSION['register'])) {
                      $data['success'] = 1;
                      unset($_SESSION['register']);
                  }
              }
  
              $this-&gt;load-&gt;view('layout/header', $data);
              $this-&gt;load-&gt;view('layout/breadcrumb', $data);
              $this-&gt;load-&gt;view('layout/body');
              $this-&gt;load-&gt;view('register', $data);
              $this-&gt;load-&gt;view('layout/close');
              $this-&gt;load-&gt;view('layout/footer');
          }
      }
  
      public function confirm($un = NULL, $conf = NULL) {
          $data['page'] = 'Confirmation';
          $data['section'] = 'None';
  
          if (isset($_SESSION['id'])) {
              redirect('/');
          } else {
              if ($un == NULL || $conf == NULL) {
                  $data['message'] = 'No account selected...';
              } else {
                  $check = $this-&gt;user_model-&gt;confirm($un, $conf);
                  if ($check == 1) {
                      $data['message'] = 'Invalid information provided...';
                  } else if ($check == 2) {
                      $data['message'] = 'User already confirmed...';
                  } else {
                      $data['message'] = 'Your account has been activated! You may now &lt;a href="' . base_url() . 'login"&gt;Login&lt;/a&gt;!';
                  }
              }
  
              $this-&gt;load-&gt;view('layout/header', $data);
              $this-&gt;load-&gt;view('layout/breadcrumb', $data);
              $this-&gt;load-&gt;view('layout/body');
              $this-&gt;load-&gt;view('confirm', $data);
              $this-&gt;load-&gt;view('layout/close');
              $this-&gt;load-&gt;view('layout/footer');
          }
      }
  } 
  </code></pre>
  
  <p>Errors Controller</p>
  
  <pre><code>&lt;?php
  
  class Error extends CI_Controller {
      public function __construct() {
          parent::__construct();
          $this-&gt;load-&gt;library('session');
      }
  
      public function index() {
          $data['page'] = 'Error 404';
          $data['section'] = 'None';
  
          if (isset($_SESSION['id'])) {
              $data['user'] = $this-&gt;user_model-&gt;get_user($_SESSION['id']);
          }
  
          $this-&gt;output-&gt;set_status_header('404');
  
          $this-&gt;load-&gt;view('layout/header', $data);
          $this-&gt;load-&gt;view('layout/breadcrumb', $data);
          $this-&gt;load-&gt;view('layout/body');
          $this-&gt;load-&gt;view('404');
          $this-&gt;load-&gt;view('layout/close');
          $this-&gt;load-&gt;view('layout/footer');
      }
  }
  </code></pre>
  
  <p>Can anyone tell me why this is happening?</p>