Reputation: 1
Hi my custom routing is not working. When i type http://localhost/sitename the default_controller routing is working but when i type http://localhost/sitename/test the browser output is 404 not found. Please help me thank you.
$route['default_controller'] = 'Traffic/test';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['test'] = "Traffic/test";
Upvotes: 0
Views: 158
Reputation: 29
Please try this code on the routes.php
$route['default_controller'] = 'welcome';
$route['test'] = 'traffic/test';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Upvotes: 1
Reputation: 3237
Please note that $route['default_controller']
expects a controller not a controller/method pair. The first thing you need to do is change that to $route['default_controller'] = 'traffic';
You may have some success using a controller/method pair, but you may run into trouble in the future as your routing increases in complexity.
also, as someone else already noted, Codeigniter naming and case convention must be followed: Even though the controller filename is uppercase (i.e., Traffic.php
) and the controller class is uppercase too (class Traffic extends CI_Controller
) whenever you make a reference to the controller such as in the default_controller
route, you must go all lowercase.
That said, your correct routing configuration should be:
$route['default_controller'] = 'traffic';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['test'] = "traffic/test";
With this configuration:
example.com
will load https://example.com/traffic/index example.com/test
will load https://example.com/traffic/testsomething
controller and the trial
method within the former)Upvotes: 0
Reputation: 1584
I had to rename my default controller php file to lowercase and the controller class name to lowercase and everything started to work. When CI looks for the default controller file, it searches in lowercase for the file; if I name my controller file "Traffic/test" instead of "traffic/test"
$route['default_controller'] = 'traffic/test';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['test'] = "traffic/test";
now above code copy and paste your routes.php
Upvotes: 0