As a web developer, It is always a very great practice to handle Page-not-found issue and create a custom 404 page to keep a good impression of your website though the link is broken. If you have a nice 404 page in your website then you can show custom message in their why link is broken? or few sweet apology words for that inconvenience.
In codeigniter, We can easily setup a nice custom 404 page with just 3 steps.
Best 404 Pages examples for web designers
Go to application/config/routes.php. Open routes.php and add following code below "default_controller" routes statement.
$route['default_controller'] = "page"; $route['404_override'] = 'not_found';
When our application failed to open a link then we need to redirect user a custom 404 controller. For our application we create a controller called "not_found" and add following code in that controller.
class Not_found extends CI_Controller {
public function __construct() {
parent::__construct();
}
//
// @ start 404 page code
//
public function index() {
$this->load->view("404_error_page.php", $data);
}
}
As i told starting of the tutorial we need keep user in our website and that's why we add some user friendly 404 text in our view file. I've add some user friendly 404 page text as example. You can change them according to your website context. Have a look -
Opss! I'm sorry! This is quite embarrassing, I must say, but I can't find the web page you are looking for. Probably just misplaced it, but who knows? What should you do at this point? Well, you have a few options:
Was this information useful? What other tips would you like to read about in the future? Share your comments, feedback and experiences with us by commenting below!
You might also like...
Md Mahbub Alam Khan is the Editor and Founder of CoolAJAX Web Blog. You can follow CoolAJAX on Twitter , on Facebook or you can subscribe via RSS .
Topics