Support
Web Development
Web Development
How to set a custom error page for your Joomla website?
If you want you can change the error page of your website. The error page can be used to lead visitors to other points of interest on your website. There isn't a setting in the Joomla control panel to do this but there is the following simple technique to achieve it.
To change the error page you will first need to create a new article which will appear in its place.
- Navigate to Content > Articles > Add New Article from the Joomla control panel menu.
- Type a Title and edit your new article the way you want your error page to look like. You can show an error image or type a message.
- Then click the Publishing tab and find the Robots metatag and change it to No index, No follow. This way search engines will not index or show your page to search results.
- Finally click the Save & Close option to save your new article.
- Navigate to Menu > Main Menu > Add New Menu Item.
- Type a Title for your error page (it doesn't matter what you fill in this field).
- Click the Select button next to the Menu Item Type tag and select Articles > Single Article.
- Then click the Select button next to the Select Article tag and select the error article you created in the previous steps.
- Next change the Status setting on the right to Unpublished to hide your error page from the main menu of your website.
- Then click the Save button.
- Now you will have to copy the URL address that is shown next to the Link field and note it somewhere to use it later on a next step.
- Finally click the Save & Close button to save your changes and close the editing page.
- To open or create the error.php file you can use the File Manager tool through cPanel or an FTP client application.
- Inside this file you should add the following lines of code for your error page.
defined('_JEXEC') or die('Restricted access');
if ($this->error->getCode() == '404') {header('Location: /link');
exit; } - Change the link field with the URL address you copied in the previous step above.
- Finally save the error.php file.