Custom 404 page in codeigniter
Helo,
I found this in the internet when I need to custom my 404 page . Because the default 404 page from codeigniter is so ‘default’
.
When the application can not found the page requested, it handle by the Exceptions in the codeigniter , function show_404.
You can find the file in the ‘./libraries/Exceptions.php’ .
In order to create your own 404 page, you just need to override the function show_404($page = ”) .
How we do that ?
You just need to create a file named : ‘MY_Exceptions.php’ , and put it in the folder ‘./application/libraries’.
And the content of the file should be like this :
<?
class MY_Exceptions extends CI_Exceptions{
public function __construct(){
parent::__construct();
}
function show_404($page = ''){
redirect('404','refresh'); // you can change this with what you want
exit;
}
}
?>
3 Comments
Other Links to this Post
RSS feed for comments on this post. TrackBack URI


By Nazmul, October 26, 2010 @ 5:46 pm
Function redirect() not working here. Call to undefined function is showing up. Even get_instance is not working.
By dedy, October 26, 2010 @ 6:04 pm
sorry, you right.
just use standar redirection then.
header(’Location: http://www.your-domain.com/your-404-page.php‘);
regards
By muhammad furqan freed, December 27, 2011 @ 2:34 pm
you can’t use base_url() in 404 page
you have to use this:
$this->config =& load_class(’Config’);
echo $this->config->item(’base_url’);