Because you can't avoid all the 404 errors on your site, it's always smart to keep your visitors into your pages. To help you to create a custom 404 error page on your website, I've wrote this fast tutorial.
It might be interesting to display a nice 404 error page to keep longer on your website your lost visitors . In few steps and with a 100% Joomla solution, we gonna redirect our lost visitors to a new page, specificly created and totaly integrated to our template.
Let's go!
How To Create a Custom 404 Error Page in Joomla
#1 Create a new menu item
- Open your admin panel and navigate to Menu, then Main menu and select the sub-menu Add New Menu Item,
- Open the tab Link Type and for the parameter Display in Menu, select NO,
- Indicate the name of your menu item (for example: 404 error page),
- For the parameter Menu Item Type, click on the blue button Select and then, click on Articles and on Single article,
#2 Create the new 404 article
- Click on Create to create your new article,
- First, indicate a title for your article (for example: 404 error article),
- Add your content in the text area and fill all the relevant infos you may need for your article (meta description, author, etc.),
- Once you've done, click on the blue button Save & Close in the bottom of the popup,
- Click on the green button Save on the top left of your page,
Now, Joomla had generated the URL of your article index.php?option=com_content&view=article&id=XX
(where XX is the ID of your article). Select and copy it to your clipboard.
- Click on the Save & Close button.
In the list of the menu items, note the ID of your 404 menu item. Copy it.
#3 Edit the template
- From your admin panel, navigate to Extensions, then Templates and Templates,
- Click on your template to open it,
- In the left list, click on error.php to open this file in the editor,
- Just right after:
defined('_JEXEC') or die;
add this code:
if (($this->error->getCode()) == '404') { header('Location: ' . Jroute::_("index.php?option=com_content&view=article&id=XXItemid=YY", false)); exit; }
Check that the XX is the ID of your article and the YY is the ID of your menu item created in the previous step.
- Click on the Save & Close button.
Conclusion
Open any page of your website and add any dummy contenu in the URL. Your 404 error page must be displayed now.
For information, a 404 error page is also a good occasion to display something useful, informative, fun or completly offbeat for your visitors.
Don't hesitate to post your custom 404 error pages in the comments below.
How To Create a Custom 404 Error Page in Joomla