Kohana 3-重定向到404页面 [英] Kohana 3 - redirect to 404 page

查看:83
本文介绍了Kohana 3-重定向到404页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索互联网后,我没有找到问题的答案. 例如,在基本拼写形式中,如果您转到http://yoursite/welcome/,则会看到hello world,但是如果键入http://您的网站/welc om /,您会看到Fatal error: Uncaught HTTP_Exception_404 [ 404 ]: The requested URL welcom/index was not found on this server. ~ SYSPATH/classes/kohana/request/client/internal.php [ 94 ] thrown in

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 found on this server. ~ SYSPATH/classes/kohana/request/client/internal.php [ 94 ] thrown in

如果用户输入了错误的地址,如何从这里将用户重定向到404页面?

From here, how can I redirect user to 404 page if he type wrong address?

Kohana 3.1.3.1

Kohana 3.1.3.1

推荐答案

这是我们的操作方式:

  1. 声明我们自己的异常处理程序 bootstrap.php或模块的init.php中的某个位置.现在,所有应用程序异常都将发送到Kw_Exception_Handler::handle().

  1. 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().

异常处理程序分析异常类型(使用getCode()方法)并使用特殊的

Exception handler analyses exception type (using getCode() method) and creates a new HMVC request with special error controller, for example ('error/404').

您还可以添加对AJAX调用的检查,并返回带有错误文本的json结构.

Also you can add check for AJAX calls and return json structure with error text.

PS. 本用户指南教程可能会有所帮助.

PS. This userguide tutorial may be helpful.

这篇关于Kohana 3-重定向到404页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆