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

(06-20-2017, 02:12 AM)wolfgang1983 Wrote:
(06-20-2017, 02:05 AM)reactionstudio Wrote: 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.

Thanks that works also.

This will work, but you are both missing the fact that the 404_override and show_404 are not directly related. Setting the one does not change the workings of the other. IMHO changing the show_404 to fix something that is not broken because of a lack of knowledge is not the way to do things.

Instead create a show_notfound() method that will handle the redirect to your custom Controller. This way you can keep using the show_404 as is, also within your custom Controller without causing an infinite redirect loop.
Reply


Messages In This Thread
404 Override Not Working - by wolfgang1983 - 06-20-2017, 01:18 AM
RE: 404 Override Not Working - by reactionstudio - 06-20-2017, 01:32 AM
RE: 404 Override Not Working - by wolfgang1983 - 06-20-2017, 01:33 AM
RE: 404 Override Not Working - by reactionstudio - 06-20-2017, 01:49 AM
RE: 404 Override Not Working - by wolfgang1983 - 06-20-2017, 01:59 AM
RE: 404 Override Not Working - by reactionstudio - 06-20-2017, 01:52 AM
RE: 404 Override Not Working - by wolfgang1983 - 06-20-2017, 02:00 AM
RE: 404 Override Not Working - by Martin7483 - 06-20-2017, 02:00 AM
RE: 404 Override Not Working - by wolfgang1983 - 06-20-2017, 02:03 AM
RE: 404 Override Not Working - by reactionstudio - 06-20-2017, 02:05 AM
RE: 404 Override Not Working - by wolfgang1983 - 06-20-2017, 02:12 AM
RE: 404 Override Not Working - by Martin7483 - 06-20-2017, 02:21 AM
RE: 404 Override Not Working - by reactionstudio - 06-20-2017, 02:37 AM
RE: 404 Override Not Working - by Martin7483 - 06-20-2017, 02:10 AM
RE: 404 Override Not Working - by Martin7483 - 06-20-2017, 02:54 AM
RE: 404 Override Not Working - by reactionstudio - 06-20-2017, 03:26 AM
RE: 404 Override Not Working - by Martin7483 - 06-20-2017, 04:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB