Reputation: 309
For a long time I'm trying to enable custom 404 page for my joomla 2.5 website, because default red error page was not an option.
I enabled it, however, it shows only if user enters site.com/wrong_page and if users enter url of the following structure site.com/wrong_page/wrong_page it doesn't show anything, just blank empty page.
So, If user goes to a page "Goods" and then goes to unexisting item site.com/goods/wrong_itemid it wouldn't show custom error, it shows nothing, but if user opens site.com/wrong_link he will see custom error page.
Please, help me to sort this out.
I used the following in error.php:
switch ($this->error->code) {
case '404':
header('location: /404-page');
break;
case '500':
include('500.php');
break;
case '403':
include('403.php');
break;
default:
header('location: /404-page');
}
Upvotes: 2
Views: 831
Reputation: 25475
This is what I did in Joomla 2.5
create your custom '404' Article
create a new unpublished menu item which links to this new 404 Article and 'apply' your changes. Copy the URL for this page (index.php?optio...)
in your Joomla installation, copy the error.php file from the templates/system directory to your template directory.
Edit the error.php file and add the following code immediately under the 'restricted access' line:
if (($this->error->getCode()) == '404') {
header('Location: /index.php?option=com_content&view=article&id=xx');
exit;
}
UPDATE
The above technique is intended as an easy way to make a custom page. You can use the built-in Joomla text editor and the page will match your site styling. @Flimm has correctly pointed out below that the page will no longer give a 404 HTTP header. If you are concerned about this, another option is:
- in your Joomla installation, copy the error.php file from the templates/system directory to your template directory.
<body>
tag however you like.Good luck!
Upvotes: 2
Reputation: 8282
Try to set it using htaccess.
ErrorDocument 404 /page404.php
ErrorDocument 500 /page500.php
Hope it helps..
Upvotes: 1