We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

spaces in uri routing

Hi, Following cases all assume that the controller class does not exist.

Throws exception. /controller/method/something

Gets routed to default controller. /contr%20oller/method/something

So does this /controller/met%20hod/something

You can see it in sample app INVO.

Is this what you would expect ? I am on a Mac/Apache 2.2



Phalcon\Mvc\Router provides default routes (https://docs.phalcon.io/en/latest/reference/routing.html#default-behavior), when an invalid URI is passed and these routes aren't matched, like in /contr%20oller/method/something, the router returns the default controller and action (index and index). You can change the not-found paths this way: https://docs.phalcon.io/en/latest/reference/routing.html#not-found-paths


Thank you for your help ... according to what you say there if i get it correctly ;)


should NOT throw an exception but get routed to the default controller class just like /contr%20oller/method/something does. which is index and index.

Adding $router->notFound() does not seem to effect the behaviour of what happens and /controller/method/something still gives me "PhalconException: ControllerController handler class cannot be loaded"

//Setup a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function(){
    $url = new \Phalcon\Mvc\Url();
    return $url;

$di->set('router', function(){
$router = new \Phalcon\Mvc\Router();
//Set 404 paths
        "controller" => "index",
        "action" => "index"


return $router;



Adding this will solve this problem becuase I can catch the exception and rout a different way ...

$di->set('dispatcher', function() use ($di) {

    $eventsManager = $di->getShared('eventsManager');

    // If the path does not match a pre-defined controller, send it to a specific controller for handling
        function($event, $dispatcher, $exception){
            switch ($exception->getCode()) {
                case Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                case Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                            'controller' => '[CONTROLLER_NAME_HERE]',
                            'action'     => '[ACTION_NAME_HERE]',
                    return false;

    $dispatcher = new Phalcon\Mvc\Dispatcher();

    return $dispatcher;

It is from here: https://forum.phalcon.io/discussion/2029/routing-non-controller-urls-to-page-controller-for-database-stor

But is this the way to do it properly ...?