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

前端 未结 9 2070
抹茶落季
抹茶落季 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:49

    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:

    load->view('notfound'); 
            }
    
    }
    

    Now, I replaced $route['404_override'] = ''; to $route['404_override'] = 'error'; in application/config/routes.php.

提交回复
热议问题