CakePHP 2.x Custom PagesController & Routing I want to direct all requests that haven't got a valid controller action to my custom page controller.  

I.e. I want /pages/new &amp; /users/login etc to work correctly, but a request for /foo or /foo/bar should be directed to /pages/display/$path.

The following code works, but I'm pretty certain I'm not doing something the right way(tm).

// In app/Config/routes.php
Router::connect('/', array('controller' =&gt; 'pages', 'action' =&gt; 'displayHome'));

$controllerList = App::objects('controller');
foreach ($controllerList as $controller) {
    $contstr = substr($controller, 0, strlen($controller)-10);
    $contstr = Inflector::tableize($contstr);
    if($contstr != 'app') {
        Router::connect('/'. $contstr, array('controller'=&gt;$contstr));
        Router::connect('/'. $contstr .'/:action', array('controller'=&gt;$contstr));
        Router::connect('/'. $contstr .'/:action/*', array('controller'=&gt;$contstr));

        // FIXME: Check if admin routing is set
        Router::connect('/admin/'. $contstr, array('controller'=&gt;$contstr, 'admin'=&gt;true));
        Router::connect('/admin/'. $contstr .'/:action', array('controller'=&gt;$contstr, 'admin'=&gt;true));
        Router::connect('/admin/'. $contstr .'/:action/*', array('controller'=&gt;$contstr, 'admin'=&gt;true));
    }
}

Router::connect('/**', array('controller'=&gt;'pages', 'action'=&gt;'display'));


Would someone please be able to review this and tell me if this is okay/horribly wrong?
Use a pattern
The general principle is fine, though it won't handle plugin routes (which I assume isn't a problem)
However instead of a loop (and therefore defining 6 routes per controller) a parameter for the controller name can be used which will be more concise and likely overall more performant. The code could be rewritten like this:
// Define a home route
Router::connect('/', array('controller' =&gt; 'pages', 'action' =&gt; 'displayHome'));

// Generate a regex-like controller name pattern (e.g. &quot;posts|comments|users&quot;)
$controllerList = App::objects('controller');
$controllerList = array_map(function($c) {
    return Inflector::underscore(substr($c, 0, strlen($c)-10);
}, $controllerList));
$controllerList = array_filter($controllerList, function ($c) {
    return $c !== 'app'
});
$controller = implode('|', $controllerList);

// Define normal routes
$params = array('controller' =&gt; $controller);
Router::connect('/:controller', $params);
Router::connect('/:controller/:action', $params);
Router::connect('/:controller/:action/*', $params);

// Define admin routes
$params += array('admin' =&gt; true, 'prefix' =&gt; 'admin');
Router::connect('/admin/:controller', $params);
Router::connect('/admin/:controller/:action', $params);
Router::connect('/admin/:controller/:action/*', $params);

// Define catchall
Router::connect('/**', array('controller'=&gt;'pages', 'action'=&gt;'display'));

In this way there are 8 routes in total, no matter how many controllers there are in the application.