How to create custom 404 page in CodeIgniter ?
We often see the 404 error page while using websites. This error page will encounter only when we navigate to a broken link. In CodeIgniter, it is possible to create a custom 404 page to change the look of the 404 page. So in this article, we will look into how to create the custom 404 error page.
In order to create a custom 404 error page, we need to do three steps:
View: In the View section, we create an error404.php page in the application/views/directory which will be displayed when any problem occurs while navigating between URLs. The standard error page doesn’t contain any CSS. In order to add styles and make the 404 Error page more attractive, a custom page can be created. Below is the HTML code that also consists of Internal CSS.
Controller: In Controller phase, we create a customError404.php in application/controllers/directory. Inside the ccustomError404.php code, in index() method load error404 view and also execute $this->output->set_status_header(‘404’). Let’s look at the code of controller.
Route: In this step, we need to edit the route.php file which is present in the application/config/ directory and assign the custom controller customError404.php to $route[‘404_override’].
- Open application/config/route.php
- Edit it to $route[‘404_override’]=’customError404.php’;
Output: The custom 404 Error page we created in this article is look like:
Please Login to comment...