December 12

4 comments

Quick redirect to your home page in Joomla for 404 errors

By Christopher Mendla

December 12, 2012


Last Updated on December 1, 2019 by Christopher G Mendla

Joomla provides an ugly 404 page that will probably cause most viewers to go elsewhere.

There are some more elegant solutions to replacing the 404 page than the one I’ll outline here. However, this is quick and easy.

This solution will only work if you are running Apache and have access to your configuration files. This solution is based on a Joomla 2.5.7 installation. Other versions may require a different approach

  • Locate your error.php.  It will be locate in a folder such as /var/www/html/templates/system
  • Back up the error.php file. (Ftp it down, rename it to error.old, ftp it back up)
  • Locate the following lines

defined(‘_JEXEC’) or die;
if (!isset($this->error)) {
$this->error = JError::raiseWarning(404, JText::_(‘JERROR_ALERTNOAUTHOR’));
$this->debug = false;

  • Insert a line as shown

defined(‘_JEXEC’) or die;
header (“Location: /”); exit();
if (!isset($this->error)) {
$this->error = JError::raiseWarning(404, JText::_(‘JERROR_ALERTNOAUTHOR’));
$this->debug = false;

This will redirect all 404’s to your home page. It worked fine on the first site I tried it on. I suspect there is a way to point this to a particular page instead of the home page but I haven’t had time to try to tweak it.

 

Christopher Mendla

About the author

Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}