We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Default route / not having an effect

I'm trying to set a default route like so:

$router->add("/", array(
    "controller" => "search",
    "action" => "index"
));

But it's having no effect. When I access https://mywebsite/ it still loads IndexController, indexAction instead of SearchController.

If I change the default controller than it works:

$router->setDefaultController('search');

Why the default route doesn't work?



32.2k
edited Apr '15

Even after disabling the default routes, it doesn't work:

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

After disabling the default routes, EVERYTHING that's not matched points to Index/Index.

And the default route is still not matched

For some reason I can replicate your problem when my baseUri is blank or '/' as it would be in most production. However, locally I can reroute when my baseUri has a value. Don't think this helps you but seems odd. Tried removing trailing slashes and didn't make a difference.

Where is the default route declaration in relation to others? I believe I've fixed this same issue before by moving the default to the bottom.