Reputation: 693
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;
}
?>
Upvotes: 1
Views: 9342
Reputation:
If (HTTP/1.1 403) then Web Browser (Firefox, IE, Chrome, ...) will ignore whatever
Location: (bla bla bla) is.
Do not believe ?
Assume :: you know how to produce Error Code 403 from your Joomla Site. (I mean joomla_site/bla-bla-bla :: that produce Error Code 403)
Let's ask whether Web Server gives (based on your error.php file) as follows :
... HTTP/1.1 403 Restricted Content Location: http://www.queensberry.com/restrictedcontent/ ...
Those are right based on your error.php file (I mean your error.php file works as you wish)
-- Check with telnet 80
Let's try
c:\telnet your_host:80
GET bla-bla-bla HTTP/1.1
Host: joomla_site
-- Hope this fulfill your curiosity :-)
I repeat it again :
If (HTTP/1.1 403) then Web Browser (Firefox, IE, Chrome, ...) will ignore whatever
Location: (bla bla bla) is.
Upvotes: 1
Reputation: 693
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;
}
?>
Upvotes: 5
Reputation: 10220
The Header("Location:") is causing a standard redirect to a new page. The 403 error will only be sent if it is on the page rendered by PHP. So you're effectively trying to say (with the code you posted) "The current page results in a 403 error" but then you redirect to an entirely different page altogether. Add the 403 header to http://www.queensberry.com/restrictedcontent/ and you should be good. You also need to do the same with the 404 header as well.
Upvotes: 1
Reputation: 106332
Rather than using Header("Loaction:...")
you should be rendering the "restricted content" page with an include()
or some such and then exiting. The browser isn't following the Location header after receiving a 403 most likely.
Upvotes: 6