How can I redirect a 404 Error in a custom 404 page using Codeigniter?

前端 未结 9 2080
抹茶落季
抹茶落季 2020-12-03 03:22

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

9条回答
  •  情话喂你
    2020-12-03 03:29

    First open routes.php in the application/config folder and set a custom controller name.

     $route['404_override'] = 'custom404'; //custom404 is class name. 
    

    Create a new controller and write the following code in it. The code is very easy to understand. So I am not going to explain it here.

    output->set_status_header('404'); 
        $data['content'] = 'error_404'; // View name 
        $this->load->view('index',$data);//loading in my template 
    } 
     } 
     ?> 
    

    Create a view file with name 'error_404.php' with your custom message. That is all you need to do and will be having your custom 404 page now.

提交回复
热议问题