views:

30

answers:

2

Hi there

I am working on a codeigniter app and am having some trouble wrapping my head around a routing issue. Basically I would like all routes to map to an specific controller action by default, but I would also like to able to specify an array of routes (or ideally initial url segments) which shouldn't follow this pattern.

By way of example:

If I enter domain.com/username it maps to domain.com/controller/method/show/username

If I enter domain.com/account it maps to domain.com/account

Any help very gratefully received!

James

A: 

Open config/routes.php and add the following:

$route['(:any)'] = "controller/method/show/$1";

Please see the link below for more routing concepts.

http://codeigniter.com/user_guide/general/routing.html

RobertPitt
A: 

Routes will run in the order they are defined. So in your routes file, put the routes for other controllers you still want to work above your catch-all for usernames:

$route['default_controller'] = 'home'; //so root url still works
$route['accounts'] = "accounts";
$route['accounts/(:any)'] = "accounts/$1";
...
$route['(:any)'] = "controller/method/show/$1";
Mitchell McKenna