You can use the following instructions to create a custom 404 error page for your Joomla website:
1. Create new article - create new uncategorized article through your Joomla administrative area -> Article manager called 404. You can insert desired text inside it which will be displayed when such error message occurs. When you are ready Save the article. The article will be accessible through a link similar to the following one:
http://www.yourdomain.com/index.php?option=com_content&view=article&id=XX
where XX is the ID of the article. You can save this link because you will need it later.
2. Create new Menu Item - create new Menu Item through Joomla administrative area -> Menu manager called 404 Item (you can use desired name). From the New Menu Item page you have to link this item to the 404 article which you have already created. You can do that by choosing Single article from the Menu Item Type field and after that choosing the article 404 from the Select Article filed on the right side of the page.
3. Copy the default error.php file inside the folder of your current template - you need to copy the defaulterror.php file from the ~/templates/system/ folder inside the folder of the template which you are currently using with your website. For example if you use a template called NewAtomic you will need to copy the error.phpfile from ~/templates/system/ folder to ~/templates/NewAtomic/. You can do that through your cPanel -> File manager or using an external FTP client.
4. Edit the copied error.php file and place the necessary 404 detection code - you need to edit the error.phpfile which you have copied inside your template's folder and place the following lines inside it:
For Joomla 1.5:
1
2
3
4
|
if(($this->error->code)=='404'){
header('Location: http://www.yourdomain.com/index.php?option=com_content&view=article&id=XX');
exit;
}
|
For Joomla 1.6, 1.7, 2.5:
1
2
3
4
|
if(($this->error->getCode())=='404'){
header('Location: http://www.yourdomain.com/index.php?option=com_content&view=article&id=XX');
exit;
}
|
where XX is the ID of the article.
You should place the above code according to your Joomla version at the beginning of the error.php file right after the following lines:
1
2
3
4
5
6
7
|
<!--?php<br?-->/**
* @package Joomla.Site
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC')ordie;
|
After that save the file and just browse to unexistent link from your website such ashttp://www.yourdomain.com/unexistent-link and you should see your custom error page.
Don’t forget to clear your Joomla cache through the administrative area in order to see the changes immediately.
Joomla is a powerful software that is easy to work with once you have the right host to support you. Before you lose any more time with the wrong host, check out the SiteGround Joomla hosting offer.