Reputation: 5208
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?
Upvotes: 0
Views: 434
Reputation: 101231
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.
class Kohana extends Kohana_Core
{
public static function handler(Exception $e)
{
if($e instanceof Kohana_Request_Exception)
{
Request::current()->redirect(Request::initial()->referrer());
}
}
}
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.
Upvotes: 1