How to redirect after route is good?

hey all, I examine that if my site is enabled or not, and if not, I redirect to an "under construction" module:

/** * @return */ protected function afterExecuteRoute() { if (!enabled && $this->router->getControllerName() != 'error' && $this->router->getControllerName() != 'underconstruction') { $this->response->redirect('underconstruction/index'); return false; } }

the problem is that if I type bad url, this still triggers. In case of bad url, I want to drive to 404 controller (already set). So how to examine AFTER good routing?



64.0k

you have this in your router ?

$this->router->notFound([
            'module' => 'home',
            'controller' => 'index',
            'action' => 'route404',
            'namespace' => 'fix_your_namespace_here :-)'
        ]);


12.1k

of course

you have this in your router ?

```php $this->router->notFound([ 'module' => 'home', 'controller' => 'index', 'action' => 'route404', 'namespace' => 'fixyournamespace_here :-)' ]); ```



64.0k

so your code is :

protected function afterExecuteRoute() {
    if (
        !enabled &&
        $this->router->getControllerName() != 'error' &&
        $this->router->getControllerName() != 'underconstruction'
    ) {
            $this->response->redirect('underconstruction/index');
            return false;
        }
}

now if you enter the if statment ( please check it to be sure :-) ),

can you try

$this->response->redirect('underconstruction/index', true);