Today we will be creating our own 404 error in Joomla together. It is designed so that when a user enters an incorrect path in the browser's address bar, they are redirected to a page we have prepared.

Let's get started...
First, we create an article in the general category, meaning it should not be in a specific site category, but rather inside the article directory. We name it 404-error and write any text you consider necessary for when a user lands on this page.
For example, you can include a link to the site's homepage so that the user can always return there and find the material they need.
Next, copy the path leading to our article. It should look something like this:
https://your_site/index.php?option=com_content&view=category&layout=blog&id=104&Itemid=75
You can save it in a notepad for quick copying when needed. Set the display state to "published".
Take the error.php file, which is located in the system folder (templates/system), and copy it to your template folder, for example, to templates/your_template/
In the error.php file, replace the lines by adding the following code immediately after the "restricted access" line:
if (($this->error->code) == '404') { header('Location: /index.php?option=com_content&view=article&id=75'); exit; ]
If you are using Joomla versions 1.6, 1.7, or 2.5, use the following code:
if (($this->error->getCode()) == '404') {
Use the previously copied path with the article to specify the address in the code (Location). You can find the article ID when creating the article... My entire code looks like this:
error->getCode()) == '404') { header('Location: /index.php?option=com_content&view=article&id=211'); exit; ] //get language and direction $doc = JFactory::getDocument(); $this->language = $doc->language; $this->direction = $doc->direction; ?>
The final touch is to add a line to the robots.txt file so that search engines do not find our 404 error:
Disallow: /index.php?option=com_content&view=article&id=75
Don't forget to replace the article ID when copying the code.
Was this helpful?