What is the 404 error
For a regular and even the average internet user, it is not uncommon to come across a 404 ‘page not found’ error. This error tells the site visitor that the page they are looking for no longer exists. It is a normal occurrence when site owners remove a page from their site, but a link to it is still available somewhere on the Internet. This redirects people to a non-existent page. A site transfer to another domain also results in a 404 error.
How a custom page for the 404 error helps
Even though the 404 error is a trivial one, leaving it unaddressed can have considerable implications for your website’s performance. Here is how having a custom page for Error 404 helps:
- Error 404 is not a direct variable in determining your site’s SEO score and ranking. However, it indirectly has a lot of impact on whether your site gets properly crawled or not. Invalid links are not crawler-friendly. Having a customized Error 404 diminishes this impact.
- It invariably enhances user experience, resulting in decreased Bounce rates.
- You can brand the error page according to the look and feel of your website.
- Customization enables you to create multilingual error pages.
Creating a custom 404 error page
To configure a custom 404 error page, you need to design the error page. Once you have the page, you should save it in the root directory of the website.
Let us assume you have created a file ‘Error-404.html’ to serve as the error page.
A typical error page looks like this in code:
This is just a template. An actual customized page involves any design elements to retain your site’s visitors. If successfully saved in the root directory of the website, the page should be visible by navigating to https://yourdomain.com/Error-404.html on a browser.
Configuring a Custom 404 error page in Apache
Configuring a custom 404 error page on Apache involves the following steps:
- Locate and open .htaccess file
The .htaccess file determines the whens and hows of information delivery to a site visitor. Connect to the server using FTP editors, and locate the .htaccess file. It is normally present in the site’s server root. If it is not there, you can create and upload the .htaccess file.
- Add ErrorDocument directive to the .htaccess file
Add the following line to the file:
If you have saved the file in the root directory itself, the added line should look like this:
The path to the site is a relative URL as evident from the example above.
Save and exit the file.
Here, we have added the Error Document directive to the .htaccess file. However, it can be added to the virtual host configuration file if you are using a virtual host or inside the main server configuration file.
If you are using a virtual host configuration file, you need to access that for your domain and locate the <VirtualHost> tag.
Add the Error directive to this tag as demonstrated here:
…
…
…
…
404 with the ErrorDocument directive denotes the error code for the error we are handling here.
Save and exit the file.
- Restart the server
If you have locally edited the .htaccess file, then it involves reuploading it to the server. Otherwise, you can simply restart the server for the changes to take effect.
To check if the process has been successful, visit https://www.yourdomain.com/Error-404.html. The page should display your customized Error 404 page, instead of the regular one.