Jun 26 2009

Custom 404 page in codeigniter


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(){
		function show_404($page = ''){
			redirect('404','refresh');  // you can change this with what you want


  • 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‘);


  • 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’);

  • By Darion, February 6, 2012 @ 10:20 pm

    Excellent. Hope you posted a bug report. Unless the PHP team are blaming it on Windows for some weird reason.

Other Links to this Post

RSS feed for comments on this post. TrackBack URI

Leave a comment

WordPress Themes