• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
custom 404 page

#1
Hi Im working on a CI site which has an admin folder at the same level as the application folder, We noticed today that the custom 404 page setup in the routes file was giving a status of 200 rather than 404.


Code:
$route['404_override'] = 'error/error404';

so I added 


Code:
$this->output->set_status_header('404'); 


to the controller / method, which seemed to work... but now the admin folder just loads this 404 page? 

How do I get access back to the admin folder please? Is there something I need to setup in the routes, or Have I setup the header status wrong?

Many Thanks Paul
Reply

#2
How do you have your controller setup? Do you have your controller named "error" and then function called "error404"? As 200 is a success response....

I have mine setup as a main controller (main.php) with all the default pages (Including error pages)

So controller main.php

PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');

class 
Main extends CI_Controller {
 
   public function __construct() {
 
       parent::__construct();
    }

    public function 
error_404() {
        
$data['page_name'] = '404 Not Found';

        
$this->load->view('static/header'$data);
        
$this->load->view('static/404');
        
$this->load->view('static/footer');
 
   }

I have more stuff for if user is logged in etc. but this is the basics of it.
Reply

#3
(11-30-2016, 01:38 PM)neodite Wrote: How do you have your controller setup? Do you have your controller named "error" and then function called "error404"? As 200 is a success response....

I have mine setup as a main controller (main.php) with all the default pages (Including error pages)

So controller main.php

PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');

class 
Main extends CI_Controller {
 
   public function __construct() {
 
       parent::__construct();
    }

    public function 
error_404() {
        
$data['page_name'] = '404 Not Found';

        
$this->load->view('static/header'$data);
        
$this->load->view('static/404');
        
$this->load->view('static/footer');
 
   }

I have more stuff for if user is logged in etc. but this is the basics of it.

Hi

yeah the controller is named error with a function named error404

Everything is working except, if you look into google chrome network inspector you will see this page when loaded is not a true 404 status, its a 200 becasue its a page that is being loaded, rather than the default 404 page that is called when a destination cant be found on the server.

SO I added the status 404 to the function and then everything seemed fine, as google was reporting the custom 404 page was indeed a status of 404..

However anything that is not in routes, or is not findable through controller / method is now also being reported as a 404 (as far as i can gather) which means the admin folder which is not part of the CI installation will no longer load its content?

Not sure how to fix this?

Paul
Reply

#4
(11-30-2016, 08:13 AM)Paul1972UK Wrote: Hi Im working on a CI site which has an admin folder at the same level as the application folder, We noticed today that the custom 404 page setup in the routes file was giving a status of 200 rather than 404.


Code:
$route['404_override'] = 'error/error404';

so I added 


Code:
$this->output->set_status_header('404'); 


to the controller / method, which seemed to work... but now the admin folder just loads this 404 page? 

How do I get access back to the admin folder please? Is there something I need to setup in the routes, or Have I setup the header status wrong?

Many Thanks Paul


On CI 3 version custom 404 does not work in sub folders place in controllers folder

Code:
$route['404_override'] = 'error404';

application > controllers > Error404.php

Code:
class Error404 extends CI_Controller {...}
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#5
** UPDATE **

ive removed the 404 override from the routes so it loads the standard 404 error page, and I have the same issue, So its nothing to do with the custom 404 page, its rather how its treating the admin folder?

I think because its outside of Ci3 installation , its classing it as 404 page.. ie.. its not in the routes, or found via controller name/method

Do you have any ideas how to fix this please?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.