Welcome Guest, Not a member yet? Register   Sign In
404 Override Not Working
#1

(This post was last modified: 06-20-2017, 01:33 AM by wolfgang1983.)

I this controller Notfound.php

Path: application > controllers > Notfound.php

I place it in the override 404 in routes


PHP Code:
$route['404_override'] = 'notfound'

But still does not show not overriding the 404.

I use virtual hosting with xampp

This is my htaccess

PHP Code:
Options +FollowSymLinks
Options 
-Indexes
DirectoryIndex index
.php
RewriteEngine on
RewriteCond 
$!^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteRule 
^(.*)$ index.php/$[L,QSA

I am not sure why it is not overriding it anysuggestions?

My template library is autoloaded


PHP Code:
<?php

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

public function 
index()
{
$this->template->set_title('Not Found!');

$this->template->render('error/not_found'$template = array());
}

I trigger the show_404 on my controller viewthread which I have attached.

Attached Files
.php   Viewthread.php (Size: 3.65 KB / Downloads: 220)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

I've noticed this sometimes too, in some circumstances it won't override to your specified controller.

Can you provide us with the code which should be triggering the 404 that you expect to be overridden, and if you edit the views/errors/html/error_404.php do you see the changes you make appear on the 404 page you're seeing?
Reply
#3

(06-20-2017, 01:32 AM)reactionstudio Wrote: I've noticed this sometimes too, in some circumstances it won't override to your specified controller.

Can you provide us with the code which should be triggering the 404 that you expect to be overridden, and if you edit the views/errors/html/error_404.php do you see the changes you make appear on the 404 page you're seeing?

Just attached it. To the main OP
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#4

when the 404 is triggered do you not see the default / stock codeigniter 404 page or does your notfound controller fail to load? What output are you seeing instead of the 404 page you're expecting?
Reply
#5

also, if you navigate to your notfound controller manually what do you see?
Reply
#6

(06-20-2017, 01:49 AM)reactionstudio Wrote: when the 404 is triggered do you not see the default / stock codeigniter 404 page or does your notfound controller fail to load? What output are you seeing instead of the 404 page you're expecting?

Yes the normal default 404 shows but not my override one.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#7

Viewing the Core code, setting a custom 404_override in ./config/routes.php does not change how the show_404() method is used.

The override is used for when your Controller can not be located. It will then load the Controller that is set in the config value.
This is not what is happening in your case, because CI can locate the controller.

Look at the docs https://codeigniter.com/user_guide/gener...l#show_404

What you need todo is create your own show_404 method or redirect to your custom Notfound controller instead of calling show_404 and pass along any needed arguments
Reply
#8

(06-20-2017, 01:52 AM)reactionstudio Wrote: also, if you navigate to your notfound controller manually what do you see?

I see the not found page when I navigate to it just the override not working
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#9

(06-20-2017, 02:00 AM)Martin7483 Wrote: Viewing the Core code, setting a custom 404_override in ./config/routes.php does not change how the show_404() method is used.

The override is used for when your Controller can not be located. It will then load the Controller that is set in the config value.
This is not what is happening in your case, because CI can locate the controller.

Look at the docs https://codeigniter.com/user_guide/gener...l#show_404

What you need todo is create your own show_404 method or redirect to your custom Notfound controller instead of calling show_404 and pass along any needed arguments

Thanks for that will look into it.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#10

(This post was last modified: 06-20-2017, 02:08 AM by reactionstudio.)

If you create the file: application/core/MY_Exceptions.php with the following code what happens?

PHP Code:
<?php


class MY_Exceptions extends CI_Exceptions {

    function 
__construct() {

        
parent::__construct();

    }

    public function 
show_404($page ''$log_error TRUE)
    {
        if (
is_cli())
        {
            
$heading 'Not Found';
            
$message 'The controller/method pair you requested was not found.';
        }
        else
        {
            
$heading '404 Page Not Found';
            
$message 'The page you requested was not found.';
        }

        
        if (
$log_error)
        {
            
log_message('error'$heading.': '.$page);
        }
        
        if( 
is_cli() ) {

            echo 
$this->show_error($heading$message'error_404'404);

        } else {
            
header("HTTP/1.0 404 Not Found");
            
            
            
header('location: http://www.yoursite.com/notfound');

        }
        exit(
4); // EXIT_UNKNOWN_FILE
    
}



dont forget to replace www.yoursite.com with your applications domain. If it works you'll need to change how the base_url is passed in but this should be enough to see if it makes progress towards a solution.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB