Regular task is keep all routes to controller action is normall way, and all other links used as a link by name of user profile for example.

 So /controller1/action1 should redirect to action1 of controller1, and /username1 or /username2 should open profiles of users.

First of all i create component with function that return list of all controllers. Code is based on Felix blog post (thinkingphp.org)

<?php
class UtilsComponent extends 
Object
{

    var $controller

    function startup(&$controller) {
        
$this->controller = &$controller
;
    } 

    function listControllers() {
        
$Configure =& Configure::getInstance
();
        
$controllers 
= array();
        foreach(
$Configure->controllerPaths as $path
) {
            
$controllers am($controllersarray_map(array(&$this‘__controllerize’), listClasses($path
)));
        }
        
        return 
array_unique($controllers
);
    }
     
    function 
__controllerize($file
) {
        return 
Inflector::camelize(r(‘_controller.php’$file
));
    }     
     
    
     
    
}
?>

Next step is add list of default routes in /config/routes.php file before most common action. In router class /bare and /ajax routes marked as obsolete but i decide to keep it. This routes create by the router class but when we  create most common route it does not work.

    loadComponent(‘Utils’);
    
$utils=& new UtilsComponent
;
    foreach (
$utils->listControllers() as $controllerName
) {
        
$controller=Inflector::underscore($controllerName
);
        
Router::connect(“/$controller”, array(‘controller’ => $controller,‘action’ => ‘index’
));
        
Router::connect(“/bare/$controller/:action/*”, array(‘controller’ => $controller,‘bare’ => ‘1′
));
        
Router::connect(“/ajax/$controller/:action/*”, array(‘controller’ => $controller,‘bare’ => ‘1′
));
        
Router::connect(“/$controller/:action/*”,array(‘controller’ => $controller
));
    } 

     
And last step is declare common  route in  /config/routes.php file.


    
Router::connect(“*”, array(‘controller’ => ‘users’‘action’ => ‘profile’
));