Kind sirs, I\'m using Codeigniter to build a blog. I might need a way to redirect a 404 error into a custom 404 page. Just like what Abduzeedo.com\'s 404 page. Is it possibl
You don't need to create any controller or modify the code, rather than modify one view file. Just placed your 404 page HTML into the application/views/errors/html/error_404.php
file.
If you want to use base_url() or any other CodeIgniter functions, initialize CI_Controller class like the below code.
<?php
$ci = new CI_Controller();
$ci =& get_instance();
$ci->load->helper('url');
?>
Simple Solution.
Create your custom error or Page not found page within view.
Create a controller for error page. Within index function load the view of error page that you already created in previous step.
Now, Go to your application/config/routes.php
you should find $route['404_override'] = '';
Its the ''
mean its calling the default error page.
Now place your controller name for error page .
It will work.
Suppose my Controller for error page is 'error'
. and view page is 'notfound'
.
So, code for Error.php
controller will be:
<?php
class Error extends CI_Controller
{
function index()
{
$this->load->view('notfound');
}
}
Now, I replaced $route['404_override'] = '';
to $route['404_override'] = 'error';
in
application/config/routes.php
.
Well you want to show your custom 404page when page not found in your website you just replace your custom file on core file which is located in application/error/error_404.php
just replace your file here and you are good to go else where you can follow other method by using routes
and custom controller for you custom 404 page
. But the shortest and easiest way is replacing the core file with custom 404error page
file