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

Default Route not Found

Hi everybody, I'm a beginner so it's possible that there is an obvious answer to my question. I have a problem with the following route, which should be matched for www.mydomain.com

        '/' => array(
            'params' => array(
                'controller' => 'index',
                'action'     => 'redirectIndex',
            'name'   => 'redirect',

This is the corresponding index controller action

    public function redirectIndexAction()
        return $this->response->redirect('en/', 301);

Somehow the redirect to www.mydomain.com/en/ is not working. But the notFound action of the index controller is executed. What could be my mistake?

Many thanks, Max

Not 100% sure but I have noticed www.domain.com/ and www.domain.com (with and without the / at the end) react two different ways.

Try creating blank route one as well '' => array( instead of '/' => array(

I added the blank route but it's stil not working. Somehow all other routes such as

       '/{language:[a-z]{2}}' => array(
            'params' => array(
                'controller' => 'index',
                'action'     => 'index',
            'name'   => 'index',

are working fine.

Unfortunately I'm still stuck with this. I noticed that the route is working for www.domain.com/index.php but not for www.domain.com/ ? Maybe there is an issue with my htaccess or my server config? Many thanks for your help! Max

Yeah sorry not sure how to help, is that a config file that you are making then setting up routes with?

Btw, I am not sure you should be seting the / or default that way. In the route setting in your bootstrap file you can do :

$router->setDefaultController('index'); $router->setDefaultAction('redirectIndex');

Have the exact same problem as Maximilian.

NotFound is run on domain.local/appdir, but the '/' route is matched and works fine with the appended index.php (domain.local/appdir/index.php).

I'm using a MicroApp.