PHP 重定向页面
我有一个 kohana 网站,我希望,如果有人修改当前 url(当他访问该网站时在浏览器中),并且该特定页面不存在,他应该被重定向到当前页面(他现在所在的位置) ),或在主页上,但不显示任何错误。
知道如何做到这一点吗?
i have a kohana website, and i want that, if someone modifies the current url (in the browser when he visits the website), and that specific page doesn't exist, he should be redirected to the current page (where he is now), or on the homepage, but without displaying any error.
any idea about how this can be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
指南提供了您需要采取的基本步骤。
您基本上可以通过定义一个名为
Kohana_Exception
的类来替换现有的异常处理程序。在该处理程序中,您将检查错误号,如果是 404,则根据 http 引用进行重定向。
这应该放在例如
application/classes/kohana.php
中请注意,这是基本要点。您应该对此进行扩展并检查 HTTP_Referer 是否已设置以及用户是否实际来自您的站点。
另请注意,这可能会导致混乱,因为人们通常不会注意到他们已被重定向。
检查指南以了解您应该在异常处理程序中执行的其他操作(例如,将其传递给默认处理程序)。
The guide gives the basic steps you need to take.
You basically replace the existing exception handler by defining a class called
Kohana_Exception
.In that handler, you would check the error number and if it's a 404, then do a redirect based on the http referer.
This should be placed in for example
application/classes/kohana.php
Note that this is the basic gist. You should expand on this and check if HTTP_Referer is set and based that the user actually came from your site.
Also note that this can cause confusion as people often don't notice they have been redirected.
Check the guide for other things you should do in the exception handler (for example, pass it on to the default handler.