'Show default browser 403 HTTP code page for missing controller. CakePHP 4.3

All answers I found do not cover the newest CakePHP version [4.3.8] and only handle how to change the template.

I want to show the default browser page for HTTP code 403 when the controller is missing. How to achieve it in the simplest way? No editing of the HTTP 404 template, just executing this command and that's it:

header("HTTP/1.1 403 Forbidden");


Solution 1:[1]

I think you could do this by adding a new bit of middleware which catches Cake\Routing\Exception\MissingControllerException exceptions and instead throws Cake\Http\Exception\ForbiddenException.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Greg Schmidt