Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Weird routing on index with special chars


Just found a weird case with routing on my site.

If I visit the base url:

All works fine.

If I try an undefined controller or anything with / that is not defined, it 404s properly:

Defined routes work fine:

However, any request to something undefined with a special char doesn't 404 but shows the index page:[email protected]

These types all display the homepage. I want them to 404.

I'm using FactoryDefault.

My router:

$di->set('router', function(){

    $router = new \Phalcon\Mvc\Router();

    // camelize
    $router->add('/([a-zA-Z\-]+)/([a-zA-Z\-]+)/:params', [
        'controller' => 1,
        'action' => 2,
        'params' => 3
    ])->convert('action', function($action) {
        return Phalcon\Text::lower(Phalcon\Text::camelize($action));

    return $router;

}, true);


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

    // Create an EventsManager
    $eventsManager = new Phalcon\Events\Manager();

    $eventsManager->attach('dispatch:beforeException', function($event, $dispatcher, $exception) {

        switch($exception->getCode()) {
            case Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
            case Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                    'controller' => 'error404',
                    'action' => 'index'
                return false;

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

    // Bind the EventsManager to the dispatcher

    return $dispatcher;

}, true);

Any ideas?


hi ty you must register $route->notFound()

Good luck


Well once again, Phalcon has the solution built right in. Not sure how I missed that.

Thank you