

Hi,
First off, we need to create the route for our custom urls. The route you would need to use is as follows:
<?php
// cake/app/config/routes.php
// Default route
$Route->connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
// Default pages route
$Route->connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
// Custom URL route
$Route->connect('/*', array('controller' => 'users', 'action' => 'view'));
?>
As you can see, the two default routes come first with our new route coming last.
We're not finished here yet. Since we now have this catch all in place, we need to ensure that all our controllers are treated correctly. To do so for our controllers, we add the following to routes.php:
<?php
// cake/app/config/routes.php
// Default route
$Route->connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
// Set default controller routes
$Route->connect('/users/:action/*', array('controller' => 'users'));
$Route->connect('/items/:action/*', array('controller' => 'items'));
$Route->connect('/images/:action/*', array('controller' => 'images'));
// Default pages route
$Route->connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
// Custom URL route
$Route->connect('/*', array('controller' => 'users', 'action' => 'view'));
?>
Because of our new route, anything not matching the base path route or the pages route will be routed through the view action of the users controller. We need to ensure we grab URLs that should maintain Cake's default routing.
The final step in this process would be to do some error handling. Since we're using our catch all, anything that doesn't exist is still going to try to route to our users controller. A quick bit of work on the view function of our controller will redirect the user if an invalid URL is given:
function view($username)
{
if ($user = $this->User->findByUsername($username)) {
$this->set('user', $user);
} else {
$this->redirect('/pages/error');
exit();
}
}
Best Regards
Naveen Butola
