2.14.2.17. Configure 404 page in Joomla!

You can configure 404 page by redirecting to a page created:

  1. Open the "Materials → Material manager → Create material" section:
  2. Specify the data for creating the desired 404 page:
    • "Title" is an arbitrary page title.
    • "Material" is the text that needs to be displayed on the page.
    • "Status" — "Published" (otherwise it will be impossible to access the page).
    • "Category" — the required category (for example, "Uncategorised").
    • "Access" — "Public" to allow access for all website visitors. Otherwise, they will not be able to reach the 404 page, and browser will display an infinite redirect error page.
  3. Switch to the "Display" tab and hide unnecessary elements of this page: As a rule, it is best to hide the following elements:
    • "Show labels".
    • "Introductory text".
    • "Material information title".
    • "Category".
    • "Category as link".
    • "Parent category title".
    • "Parent category title as a link".
    • "Show associations".
    • "Author".
    • "Publication date".
    • "Navigation".
    • "Show icons".
    • "Print icon".
    • "Number of views".
  4. Save the page by clicking "Save".
  5. As soon as page is refreshed and data is saved, pay attention to browser address bar and remember the page number specified after &id=X:
  6. Configure redirection to this page by specifying string /index.php?option=com_content&view=article&id=X as the address_of_the_created_page, where instead of X you should specify previously saved page number.

To create your own 404 page (without using a Joomla! template), create such a page, for example, in the root directory of the site with a name like 404-error.php, using your own layout with the required information and visual design, or by using third-party templates, for example this one.

After creating the page itself, configure redirection to it by specifying the file name as the created_page_address, for example, with the previously given example /404-error.php.

By default, the 404 error is generated using the error.php file in the theme directory, but in most cases these files have a rather complex structure that ensures correct operation specifically with this theme.

  1. Rename the error.php file of the active theme to another arbitrary name, for example error.php.bak.
  2. Copy the templates/system/error.php file to the active theme directory.
  3. Edit the file by specifying the redirect lines:
    if (($this->error->getCode()) == '404') {
        header('Location: /created_page_address');
    exit;
    }

    after the lines

    if (!isset($this->error))
    {
        $this->error = JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
        $this->debug = false;
    }
    
    $app = JFactory::getApplication();

    Instead of /address_of_the_created_page, specify required address of previously created page.

You can perform all the specified actions using the file manager or any FTP client.

Content

    (1)