0

I have the following code for my 404 it is located in error.php within the template

if ($this->error->getCode() == '404') { 
  header('Location: /images/masters/404.gif');
  exit;
}

I specifically have it looking at an image so it takes up the whole screen, as opposed to an article or the like.

My question is... how do I have this image become a hyperlink back to the homepage?

I tried the standard image links without success

if ($this->error->getCode() == '404') { 
  header('Location: <a href="/home"><img alt="404 error" src="/images/masters/404.gif" style="width: 1321px; height: 828px;" /></a>');
exit;
}

Any ideas how I can work the hyperlink into the code?

2 Answers 2

0

Your approach for dealing with the 404 errors is in a completely wrong direction. First after redirecting directly to the image file, all you have is an image file. So there is nothing html there, so we can't even talk about links and anything else html there.

Regarding why your approach is wrong, read this question/answer here: Joomla Redirect without changing url, which in its core is very similar to your situation.

1

If you want to use HTML (such as to display an image with a link) then you need to display it in a page that is outputting HTML.

It's possible in CSS/HTML to make an image take up the whole screen - linking directly to an image isn't the best way to achieve that effect.

You could either write a small, static page outside-of-Joomla and redirect to that using header if you don't feel up to editing error.php, but it is possible to update the CSS and HTML content of error.php to output only the code exactly as you want.

It isn't quite clear what you mean by "I specifically have it looking at an image so it takes up the whole screen, as opposed to an article or the like." - but error.php can display any HTML you wish. It doesn't have to have an article format.

2
  • What I got from his question is that he isn't using the error.php to output anything, instead on the top of the error.php he is redirecting the browser to the image file.
    – FFrewin
    Commented Apr 28, 2017 at 11:41
  • I understand what you're saying, but that code provided is what I have in my error.php file.
    – Iain
    Commented May 3, 2017 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.