How to create custom 404 page in Codeigniter 4
custom 404 page in Codeigniter 4
In this tutorial, I will show you how you can create a fully customized 404 error page in Codeignitor 4 (how to create a custom 404 error page in CodeIgniter 4). I will start by creating a controller and then proceed to set up routes.
Why 404 error not found
404 not found is HTML error code indicating a special condition in which the connection between the server and the client is working correctly, but the server could not find the resource requested by the client.
The underlying causes of the error are many, but the normal process is the same in all cases. The server has received a request for a resource that does not exist on the server hosting PHP. A very common cause of this condition is broken links that point to pages or resources that have been removed (or taken down) by the website administrator. CodeIgniter 4 displays a simple 404 error page whenever a user navigates to a broken link.
So lets start coding
create 404.php file inside directory of your Codeigniter 4 project. And paste below code.
create or modify inside “public/css” directory in Codeigniter 4 project, and paste below code:
Download background image and paste into “public/img” directory in your codeigniter 4 project.
modify your Routes.php file inside “app/config” directory of your codeigniter 4 project. And copy code from below code starting from line number 22 to 24.
That’s it, Now your custom 404 not found page is ready. You will get output like below screenshot.
custom 404 page in Codeigniter 4
You can easily customize it and make it more user friendly for the user.
You can also watch my video on Youtube about custom 404 page in Codeigniter 4
The conclusion
In this small article, I have demonstrated a custom designed 404 error page for your Codeigniter 4 project. A custom 404 error page is an ideal way to retain visitors to the website and redirect them to the appropriate pages on the website. This greatly reduces the bounce rate of websites and ensures that visitors are interested in your website. If you have further questions and questions about creating custom 404 pages for Codeigniter 4 projects, post them in the comments below.
Originally published at https://learnpainless.com on June 13, 2020.