Kohana 3 - redirect to 404 page
After searching internet I haven't found answer to my question.
For example, in base complectation if you go to http://yoursite/welcome/
you'll see hello world
but if you type http://yoursite/welcom/ you'll see Fatal error: Uncaught HTTP_Exception_404 [ 404 ]: The requested URL welcom/index was not fo开发者_运维知识库und on this server. ~ SYSPATH/classes/kohana/request/client/internal.php [ 94 ] thrown in
From here, how can I redirect user to 404 page if he type wrong address?
Kohana 3.1.3.1
Here is how we do it:
Declare our own exception handler somewhere in bootstrap.php or module's init.php. Now all application exceptions will be sent to
Kw_Exception_Handler::handle()
.Exception handler analyses exception type (using
getCode()
method) and creates a new HMVC request with special error controller, for example ('error/404').
Also you can add check for AJAX calls and return json structure with error text.
PS. This userguide tutorial may be helpful.
I think this will work for you: How to setup a custom 404 page for a Kohana v3 app
I think this is referring to Kohana 3, though. I think you need to use HTTP_Exception_???
and execute()
is called in index.php by default (by Request::factory()
, not Request::instance()
. I think you can work it out from there.
精彩评论