Calling Joomla!'s Default 404 Page

by Zachary Draper   Last Updated April 16, 2018 07:10 AM

I am working on a custom component that displays pages to the user on the front-end. It is possible that a user may try to access a page of the component that no longer exists, and in these instances, I would like to show the 404 page that is already setup. How do you cause Joomla! to display the 404 page from a custom component? Just like with a normal 404 error, I am looking for the address bar not to change. Being able to do this from the model would be preferable.

Thank you for your help.

Answers 2

In your Joomla installation directory reach templates/themeXXX/error.php file.

Edit the error.php file as shown below, locate this line of code: If you don't want to change address bar url then you can use below code

if (($this->error->getCode()) == '404') {
header("HTTP/1.0 404 Not Found");
echo file_get_contents(JURI::root().'alias-of-404-article-page');
Sudhir Sapkal
Sudhir Sapkal
April 16, 2018 13:00 PM

In order to call the 404 error page from your component, simply raise a 404 error using JError. For example:

JError::raiseError(404, JText::_('COM_CONTENT_ERROR_ARTICLE_NOT_FOUND'));
Zachary Draper
Zachary Draper
April 18, 2018 21:58 PM

Related Questions

Restore Backup Joomla 2.5 Errors PHP

Updated September 09, 2016 08:06 AM

Custom 404 page shows unselected modules

Updated March 21, 2017 16:10 PM