Custom 404 not showing in Codeigniter on live server -


i'm working on codeigniter project , want show custom 404 page if route not found. working fine on localhost when upload project on live server it's not showing anymore. on live server shows me default 404. , url generate example.com/my404 not show custom 404. please me find out missing something. valuable answer.

here view file error_404.php

<!doctype html>     <html lang="en">     <head>     <meta charset="utf-8">     <title>404 page not found</title>     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">     <style type="text/css">       body       {         padding: 0px;         margin:0px;       }        h1       {         padding: 0px;         margin: 0px;         font-size: 15px;         text-align: center;         font-weight: 600;         font-family: sans-serif;         color: #003a99;       }        #container       {         width: 100%;         background-position: top center;         background-repeat: no-repeat;         background-attachment: local;         background-size: cover;       }        .web       {         padding-top: 10px;         padding-bottom: 85px;       }        span       {         color:#333;       }        .heading       {         color:#333;       }     </style>     </head>     <body>         <div id="container" class="img-responsive" style="assets/images/background-image:url(404-page-not-found2.jpg);">         <img src="assets/images/404-page.png" class="img-responsive"/>         <h1 class="heading">the page you’re looking went fishing!</h1>         <h1 class="web">go <a href="<?php echo base_url();?>"><span>www.vpacknmove.in</span></a><h1>         </div>     </body>     </html> 

here controller file my404.php

<?php class my404 extends ci_controller {     public function __construct()     {         parent::__construct();     }      public function index()     {         $this->output->set_status_header('404');         $this->load->view('error_404');//loading in template     } } ?> 

and routes

$route['404_override'] = 'my404'; $route['default_controller']      = 'home'; 

try lowercase controller name in route:

$route['404_override'] = 'my404'; 

report if doesn't solve problem.

regarding if need customize 404 generated when there no matching route, i've created file /application/core/my_exception.php:

<?php defined('basepath') or exit('no direct script access allowed');  class my_exceptions extends ci_exceptions {      /**      * class constructor      */     public function __construct()     {         parent::__construct();     }      // --------------------------------------------------------------------      /**      * 404 error handler      * -----------------      * method has been extended if use show_404      * function, styled/custom 404 page shown.      */     public function show_404( $page = '', $log_error = true )     {         if( is_cli() )         {             $heading = 'not found';             $message = 'the controller/method pair requested not found.';         }         else         {             $heading = '404 error - page not found';             $message = 'the page or resource looking not found on server.';         }          // default log this, allow dev skip         if( $log_error )         {             log_message('error', $heading . ': ' . $page );         }          if( is_cli() )         {             echo $this->show_error($heading, $message, 'error_404', 404);            }         else         {             $ci = &get_instance();              $ci->output->set_status_header('404');              $view_data = [                 'heading' => $heading,                 'message' => $message             ];              $data = [                 'doc_title' => ['pre' => '404 error - page not found - '],                 'extra_head' => '<meta name="robots" content="noindex,nofollow" />',                 'content' => $ci->load->view( 'errors/html/error_404', $view_data, true )             ];              $ci->load->view('templates/main', $data);              echo $ci->output->get_output();         }          exit(4); // exit_unknown_file     }      // --------------------------------------------------------------------  } 

notice way i've done it, i'm nesting error_404 view inside template created. that's way it. you'd replace part use when create pages in application (usually controller).


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -