Custom error pages, e.g. HTML errors 404 and 500

Joomla! Templates modifications

Custom error pages, e.g. HTML errors 404 and 500

Postby anvj » Sun Feb 07, 2010 11:52 pm

You can create specific Joomla! articles to be displayed upon the page not found (HTML error 404), View not found [name, type, prefix]: more-about-joomla,html,contentView (HTML error 500), or any other error. The instructions below will create custom error pages for both HTML errors 404 and 500.

  • Create two new Joomla! articles for HTML errors 404 and 500. Example:
  • Locate and modify the error.php file within the currently used template, e.g. templates/system/error.php as follows:
    Original code:
    Code: Select all
    // no direct access
    defined( '_JEXEC' ) or die( 'Restricted access' );
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    New code:
    Code: Select all
    // no direct access
    defined( '_JEXEC' ) or die( 'Restricted access' );
    if ($this->error->code == '404') {
    header('Location: '.$this->baseurl.'/index.php?option=com_content&amp;view=article&amp;id=47');
    exit;
    } elseif ($this->error->code == '500') {
    header('Location: '.$this->baseurl.'/index.php?option=com_content&amp;view=article&amp;id=48');
    exit;
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  • Make sure to disallow these two pages from being indexed by search bots. Add the following two lines to your robots.txt file:
    Code: Select all
    Disallow: /index.php?option=com_content&view=article&id=47
    Disallow: /index.php?option=com_content&view=article&id=48
anvj
Site Admin
 
Posts: 7
Joined: Thu Feb 04, 2010 4:21 pm
Location: Inside of Joomla!

Return to Templates

Who is online

Users browsing this forum: No registered users and 1 guest

cron