Search code examples
phpjoomlawebserverhttp-status-code-404http-status-code-403

Whats wrong with this 403 error redirect


Hi have created a error.php for joomla to redirect 404 errors etc to a joomla article. The code below works for a 404 error, but a 403 returns a blank page. I can navigate to the page directly outside my script so it must be either my code or how it is interactive in it's environment.

Thanks Stephen

defined( '_JEXEC' ) or die( 'Restricted access' );
if ($this->error->code == 404)
{
Header( "HTTP/1.1 404 Not found" );
header("Location: http://www.queensberry.com/misc/filenotfound/");
} else if ($this->error->code == 403) {
Header( "HTTP/1.1 403 Restricted Content" );
Header( "Location: http://www.queensberry.com/restrictedcontent/" ); 
} else {
echo "hello world error code = " . $this->error->code;
}
?>

Solution

  • I appreciate everyone's help, but the answers were sending me in a different direction to what I was hoping for. I wanted to continue using Joomla's error.php file as the destination for Joomla errors but instead of formatting the page to look like it was part of the site I wanted to redirect to Joomla content.

    In the end I found what I needed was an exit; in my script. So here is the error.php as it is now working.

    defined( '_JEXEC' ) or die( 'Restricted access' );
    if ($this->error->code == 404)
    {
    Header( "HTTP/1.1 404 Not found" );
    header("Location: http://www.queensberry.com/misc/filenotfound/");
    exit;
    } else if ($this->error->code == 403) {
    Header( "HTTP/1.1 403 Restricted Content" );
    Header( "Location: http://www.queensberry.com/restrictedcontent/" ); 
    exit;
    } else {
    echo "hello world error code = " . $this->error->code;
    }
    ?>