4
votes

Routes not working and default controller showing error 404 when I am setting welcome as a default controller then all routes defined with the welcome controller working but my other routes and url not working.

$route['default_controller'] = "welcome";
$route['testRoute'] = 'welcome/test';
$route['testRoute/(:num)'] = 'welcome/test/$i';

All above routes are working with only welcome controller.

$route['default_controller'] = "login";
$route['loginMe'] = 'login/loginMe';
$route['logout'] = 'user/logout';

Showing error 404 for all controllers and functions.

2
Could be a number of things... Are your login and user controller files 1st letter uppercase. It might help if you show those. - TimBrownlaw
All name spaces are correct. Everything in working fine in localhost but on live server except welcome controller for everything its showing error 404. - Roshan Lal
what's live servr URL ?? - Abdulla Nilam
So your login Controller is named Login.php and your user controller is named as User.php. So what system is your local development server running on? - TimBrownlaw

2 Answers

4
votes

If you put index.php after domain this will work.

http://www.example.com/index.php/login/

You should remove index.php from url by replacing in config and .htaccess

replace in config.php

$config['index_page'] = 'index.php';

by

$config['index_page'] = '';

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
1
votes

This is what worked for me:

  1. In config.php of config folder, use: $config['enable_query_strings'] = FALSE;
  2. Use $config['uri_protocol'] = 'AUTO';
  3. Use $config['index_page'] = '';
  4. Also remember to set your base url. Mine is: $config['base_url'] = 'http://localhost/code';
  5. Finally use the following htaccess file:

    <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /code/index.php/$1 [L] </IfModule>

NB: Remember to edit your path to index.php in the htaccess file. Hope this works for you