Skip to content
Advertisement

Codeigniter routes not working as expected

I’m very confused as the documentation for this is very straight forward and simple, I must be missing something.

I have controller that I route to using routes.php like so.

$route['users'] = '/usermanager'; This works as expected, navigating to mysite/users renders my controller.

I have some front end routing to handle different tabs on the user page, so the url can have some sub routes like /users/management. The logic for this is all handled on the front end, all I need is for anything under /users to route to the same controller.

So I write it like so: $route['/users/(:any)'] = '/usermanager';

This fails and I get directed to my 404 page. I also tried specifying my route explicitly: $route['/users/management'] = '/usermanager';

Still no dice. What am I not understanding about this routing feature.

Heres my full routes.php incase there’s something i’m missing:

$route['default_controller'] = 'EdgeView';
$route['404_override'] = 'PageNotFound';
$route['translate_uri_dashes'] = FALSE;

$route['view'] = '/';
$route['list'] = '/';
$route['pictorial'] = '/';
$route['certificate'] = '/';
$route['files'] = '/';
$route['about'] = '/';
$route['contact'] = '/';

$route['users'] = '/usermanager';
$route['/users/(:any)'] = '/usermanager';

Advertisement

Answer

Remove the leading slash in your route.

Change this

$route['/users/(:any)'] = '/usermanager';

to this

$route['users/(:any)'] = 'usermanager';
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement