Improve 404 error page display
Once you enable URL optimization
from the sh404SEF control panel, Joomla! 404 error handling is replaced by sh404SEF own page. By default, it looks like below, and there are 2 main differences with Joomla! behavior:
- The error page is displayed inside the full regular template, so that users do have all of your site regular navigation links available to select another page
- If possible, sh404SEF will add links to the pages the most similar to what the visitor requested (similar as in: "with similar URLs")
The latter is a terrific help to visitors. Many times, a 404 is only the result of a typo in a bookmark, and sh404SEF will find and propose the correct link in such case. Likewise, if the article or content requested has moved (and you haven't setup a redirect to the new URL), sh404SEF will probably find the new URL and offer it as #1 choice.
Modifying the error page content
The content of that page can be modified in sh404SEF configuration:
You can use the following tags while editing this error page:
{%sh404SEF_404_URL%}
will be replaced by the url the visitor requested, the one that we could not find{sh404sefSimilarUrls}
will be replaced by a list of urls found in the database that are similar to the one requested but not found. If none are found to be similar, nothing will be displayed and the tag removed. -{sh404sefSimilarUrlsCommentStart}
and{sh404sefSimilarUrlsCommentEnd}
: everything you put between those two tags will be displayed only if some similar urls are found
Finding similar URLs is done by an sh404SEF plugin. There are a few parameters available to adjust its behavior. You can change them directly in the plugin parameters page, using Joomla! plugin manager (Extensions > Plugins manager
)
Finding similar URLs can be resource intensive. If you experience high-load on your database server, you may have to disable the Similar URLs plugin
Multilingual sites
The screenshot above shows only an error page in one language. If more front-end languages are installed on your site, sh404SEF will automatically show additional tabs, with the corresponding error page content editing fields.
- Language detection to display the error page is done by the Joomla! language filter plugin. It will first see if the visitor already has a language cookie from the site. If not, it will check if the URL starts with a valid language code (eg: /fr/some-bad-url) and use that. If none of this works, then it will resort to the site default language.
- Please be sure to check out our Error page handling video which shows default behavior and changing basic settings in just a few minutes
Customizing the 404 error page output
The main content of the 404 error page is rendered with a JLayout. You can thus override it from your template. The JLayout to override is:
com_sh404sef.general.error_404_main
It contains all PHP, CSS and javascript to display the message. You should override it by placing your own error_404_main.php file in the /templates/<your_template/html/layouts/com_sh404sef/general folder. It will receive the following data:
$displayData['text'] string the main content of the page
$displayData['language_tag'] string the full language page as identified by Joomla
Customizing breadcrumb and page title
When displaying the 404 error page, sh404SEF will set the page title to The requested page was not found on our site and the breadcrumb, if you display any, to Home > Page not found.
You can modify these strings using Joomla! language strings override for the following language keys:
COM_SH404SEF_PAGE_NOT_FOUND_TITLE
, for the page titleCOM_SH404SEF_PAGE_NOT_FOUND_PATHWAY
, for the breadcrumb (also called pathway)
You can use this mechanism to either or simultaneously customize the text in your language, or provide additional versions for multiple languages.