路由codeigniter与无限的参数

I have a controller Categories with action index and params(params will contain category name) which makes my url http://localhost/categories/index/(category_name)

I want my url to be written like this http://localhost/(category_name)

But i also have sub categories and more deep level sub categories. So now my url should be written like this http://localhost/(category_name)/(sub_categories) or more deep level http://localhost/(category_name)/(sub_categories)/(sub_sub_categories)

Is there a way to route my url to unlimited params of the action.

The below code is working

$route['(.+)'] = 'categories/index/$1';

but it affects to all the controllers and no other controllers seems to be working

I want to know is there another way to achieve the same.

Thanks!

You can use uri_to_assoc(). Check this page.