Error pages are used to inform visitors to your website about site problems. Each type of problem corresponds to an established code. A visitor who accesses a non-existent URL will see a Error 404, while an unauthorized user trying to access a restricted file will see a error 401.
Apache web server automatically provides basic error pages, that you can customize. You can also call them from the .htaccess file that you have created in a more personalized way for any HTTP status code that starts with 4 or 5 (400/500).
Error pages are generally pages created in HTML, which include links to images, and which can use Cascading Style Sheets (CSS) to customize the view in the browser.
As a general rule, the .html files of the error pages are located in the main folder of the installation served by these files, although it is possible to centralize all the error pages in a specific folder and call these pages with absolute urls.
Examples of calls to common error pages:
- ErrorDocument 500 /internalerror.html
- ErrorDocument 401 /authrequired.html
- ErrorDocument 403 /forbidden.html
- ErrorDocument 404 /notfound.html
It is not recommended to use special characters or spaces in the composition of the names of these files.
The .htaccess file, responsible for calling these error files, must be located in the root folder of the Hosting.
The format of instantiation to custom error files, in the file .htaccess is:
ErrorDocument 404 /404page.html
If you handle different custom error warnings you can consider creating a folder to store the different files and instantiate them from the file .htaccess incorporating the relative path:
ErrorDocument 404 /errores/404.php
You can create a custom error page with HTML code, and then configure the error page call from .htaccess to help reduce the use of server resources needed to handle requests for pages that don’t exist.
If you make continuous queries to your database, dynamically, to check if a page exists or not, you will end up consuming a lot of Hosting resources, and the user experience will be worse with a slower loading of the site for visitors .
Some errors that you can customize through the corresponding page:
- 400 – Incorrect request
- 401 – Authorization required
- 403 – prohibited
- 404 – Not found
- 500 – Internal Server Error
All the errors that can be managed in a personalized way from cPanel:
- 400 (bad Request)
- 401 (authorization required)
- 402 (payment required)
- 403 (prohibited)
- 404 (not found)
- 405 (method not allowed)
- 406 (not acceptable)
- 407 (proxy authentication required)
- 408 (timed out request)
- 409 (conflict)
- 410 (lost)
- 411 (required length)
- 412 (failed precondition)
- 413 (request entity too large)
- 414 (Request URI too large)
- 415 (incompatible multimedia type)
- 416 (request interval not feasible)
- 417 (failed expectation)
- 422 (non-actionable entity)
- 423 (locked)
- 424 (failed dependency)
- 500 (Internal Server Error)
- 501 (not implemented)
- 502 (wrong gateway)
- 503 (service not available)
- 504 (timed out for the gateway)
- 505 (HTTP version is not supported)
- 506 (variant also negotiates)
- 507 (insufficient storage)
- 510 (not extended)
It is not necessary to create custom pages for all existing errors, but only for the usual ones such as 404 errors, for example.
What should an error page file contain?
A file displaying an error warning to the visitor must contain the file type declaration, a header , a body , and may also include statements of CSS styles to format the texts and images displayed on the screen. A typical example might be:
500Error interno del servidor
¡Vaya! Algo salió mal.
Trata de volver a cargar esta página o no dudes en contactar con nosotros si el problema persiste.
The page, if the error occurs in the browser, would look something like the following:
Edit error pages in cPanel
If you work in a cPanel-based hosting panel, you can manage the different error pages from the section Advanced, Error pages.
There are two important tabs available:
- Edit common error codes
- Show all HTTP error status codes
To edit, for example, the 404 error page, click on the corresponding element and access the HTML code edition from where you can customize or adapt it to your needs.
Labels available for customization:
- Referrer URL: <!–#echo var=”HTTP_REFERER” –>
- Visitor’s IP address: <!–#echo var=”REMOTE_ADDR” –>
- URL requested: <!–#echo var=”REQUEST_URI” –>
- Server name: <!–#echo var=”HTTP_HOST” –>
- Visitor browser: <!–#echo var=”HTTP_USER_AGENT” –>
- Redirect status code: <!–#echo var=”REDIRECT_STATUS” –>
Note that the page you are editing is .shtml and not .html.
Surely you have found yourself in your Hosting Panel, in the error logs notices of pages that do not exist and that refer to pages that are not .html but .shtml
[Fri Dec 18 02:49:30 2015] [error] File does not exist: /home/public_html/404.shtml
From your cPanel, Advanced, Error pages, you can manage them as I have explained above.
In the next video of David Noguera You can see in more detail how to use the cPanel tool to personalize these pages.
WordPress error pages
In WordPress you can customize them manually, for my taste a little elaborate, or you can do it using plugins as usual!
One of my favorites is 404page for its versatility and ease of use. Take a look at it and if you like, adopt it on your WordPress websites.
Error pages in PrestaShop
By default PrestaShop includes the following pages for handling preformatted errors:
In addition, the CMS includes custom pages embedded within the theme in use, which can also be customized, which you can find in routes such as:
- Error 404: /public_html/themes/default-bootstrap/404.tpl
In case of 404 errors, we would see the following error page embedded within the Store theme:
Recommended reading: 404 errors in PrestaShop How to manage them?
Joomla error pages
In Joomla the errors are shown embedded in the template in use and managed from the file of the same called error.php It will display custom messages for each type of common error that occurs (400/500).
You can read the official documentation of Joomla.org for managing custom error pages.
In the next video of Jhon Marreos You can see in more detail how to improve the error 404 page in Joomla.
Other not less important considerations
Don’t forget to exclude those custom error handling pages from indexing by search engines. If you have centralized all the pages in a folder, for example / public_html / errors / you can add in the file robots.txt the following line:
Another option would be to include within each error page, either .html or .shmtl (managed from your cPanel) the following code, between the labels and , to avoid indexing these pages:
With this we avoid the indexing and the tracking or tracing of the internal links that these pages may contain. However Google as a general rule does not index 404 pages, but like everything in life, it goes from the day its bots have and how Panda has dawned.
Now you understand a little better how to find and modify or customize the different error handling pages in your usual dynamic content manager. It’s time for you to put it into practice.
Faced with HTTP 404 response errors, your page content and ranking will be greatly affected, and possibly the page that returns an error will not be crawled or indexed. Google, Bing, Yahoo, etc., don’t like 404s do not forget!
Member of the Websites Are Us technical team.
Coordinator of content on the Blog and YouTube.
Technical support in CyberProtector. Teacher at Websites Are Us Learning.