How to create a 404 page in CodeIgniter

One of the must have in CodeIgniter is a custom 404 error page.

It’s really easy to do and it makes huge impact for the user.

1. Create a new Controller

Create a new controller custom404.php and fill it with the following code:

Please note this code might vary according to your application, usually you won’t have to change anything.

In the code above you can see what will be our next step…

2. Create the view

Create the file custom404view.php in your views folder and fill with HTML.

3. Edit your Routes file

Last but not least, edit your /application/config/routes.php adding the following line:

The value for this route will be the name of the controller you’ve created in the first step.

I hope you found this tutorial helpful 😉

4 Responses to “How to create a 404 page in CodeIgniter”

  1. Miguel July 13, 2014 at 8:45 pm #

    Hola, me sigue redirigiendo a la pagina de 404 de codeigniter, alguna surgerencia?

    • Rick July 16, 2014 at 10:36 pm #

      Imagino que será cosa del archivo routes. Vuelve a echarle un vistazo que esté todo bien, que se esté cargando correctamente.

      Si encuentras solución avísanos 😉

  2. saikiran October 29, 2015 at 4:36 pm #

    how to make this cutom_404 to show up all the time in whole App. I mean to over ride the default one all the time

  3. Coll December 28, 2016 at 11:00 pm #

    Line 13 of your custom404 class should be changed from:
    $this->data[‘content’] = ‘custom404view’; // View name
    $data[‘content’] = ‘custom404view’; // View name

Leave a Reply

Add <code> Some Code </code> by using this tags.