2
votes

I'm using a yii framework for a website.

My apache rewrite all request to the yii application. In my default controller I check every request and if there is content in database available a webpage will be displayed.

When there is no content available I dispay a custom 404 error page.

throw new CHttpException(404);

This works fine, but the user is redirect to the 404 error page.

Instead the request should be rewritten in yii application internally. Is this even possible? or can i maybe internally create a new application for the 404 request.

My goal is to display the 404-page with only one client request.

request domain/bla --> not available --> response with error code 404 and content from domain/404.html

Thanks for any answer in advance

1

1 Answers

0
votes

Define your error handler in the configuration
main/config.php in components section

'components' => [
    // other components
    'errorHandler'  =>      [
        'errorAction'       =>      'error/error',
    ],
]

Add an error controller with actionError method inside. Write your logic there.