Adding a 404 page not found in Codeigniter
Often a URL is requested that doesn’t have anything associated a controller in Codeigniter, for this a 404 page not found exception may be added in Codeigniter. For this we have to add our controller in application/config/routes.php. In this file we have to find $route[‘404_override’] = ”; line and place our controller here like :
$route['404_override'] = 'Hello/pageNotFound';
where our controller file (application/controllers/Hello.php) will look like this:
Example
<?php class Hello extends CI_Controller { public function index() { echo "Hello World!"; } public function pageNotFound() { echo "this is page not found page"; } }
Output
URL : http://localhost/myApp/index.php/klfsdkljfsd/dfsds
Output : this is page not found page