View Categories

How to Improve SEO With .htaccess to Set Up Custom Error Pages

A mug spilling coffee.
  • May 28, 2020
  • 0
  • by A2 Marketing Team

Error messages aren’t generally considered good for Search Engine Optimization (SEO). In fact, they’re not usually a positive in any respect. However, no matter how carefully you maintain your site, you’re likely to encounter them from time to time.

When errors do show up, there are some ways you can limit their potential effect on your site’s Search Engine Optimization (SEO). Perhaps the best way to do that is by redirecting users to a custom error page using the .htaccess file. This page can include links to popular articles, and even a sitemap to help users return to a working part of your site.

In this article, we’ll talk about what the .htaccess file is, and some of the things it can do. We’ll then explain how this file can be used to set up custom error pages and improve SEO. Let’s take a look!

An Introduction to the .htaccess File

.htaccess is short for “Hypertext Access”. It’s a configuration file that affects how a server responds to requests, and is supported by Apache-based web servers. In a nutshell, it controls the directory that it ‘lives’ in.

You can think of the .htaccess file as the doorman to an apartment building (which would be the folder or directory that contains it). When you open the door and tell the doorman (.htaccess) where you want to go, he directs you through the building (the directory) and to the proper apartment unit (the file you asked for).

Traditionally, the .htaccess file is used to control access to individual folders. A system administrator can use the file to password-protect specific directories without having to restrict everything else. In other words, if you don’t have the password, the doorman won’t let you in.

How to Redirect Users to a Custom Error Page Using .htaccess

When a request is made to the web server and it is unable to respond, it sends back an error message. If you don’t specify any type of error handling, the server will likely display a generic message like this one:

A generic 404 error page.

Getting one of these can be frustrating for end users, and doesn’t offer them much help. On the other hand, custom error pages can include fun images and links back to your site that help to keep visitors engaged. This can ease the annoyance they may naturally feel when encountering such an error.

To set a custom error page up, you’ll first need a way to redirect the normal process, and replace the generic error message with your customized one. This is where the .htaccess file comes in.

There are a couple of ways you can access this file. You can do so with a File Transfer Protocol (FTP) client like FileZilla, from your hosting cPanel, or by using a free plugin such as WP Htaccess Editor:

The WP Htaccess Editor plugin.

If you choose to use the latter method, you can start by installing and activating the plugin on your site. Then go to Settings > WP Htaccess Editor:

Using the editor to access your .htaccess file.

You can insert the HTML file for your custom error page here. All you need to do is specify which document to use with the error, like this:

ErrorDocument 404 /errors/not-found.html

In this example, “not-found.html” is the file for your custom error page. You can make and insert similar files for each of the other common errors as well, such as 400 bad requests and 403 forbidden messages.

4 Ways to Improve SEO Using a Custom Error Page

By using custom error pages, you may be able to improve your SEO rather than hurting it the next time a visitor encounters an issue. Now, let’s talk about some of the ways you can do that.

1. Link to Top Articles

Adding internal links to your error pages gives users a place to go other than clicking away from your site. You may be able to entice them with some of your other content, which is likely why they are on your site in the first place.

For example, take a look at this error page from Amazon:

Amazon's error page.

Here, Amazon piques our interest with a picture of a dog and a link to Meet the dogs of Amazon. If you’re curious and you like dogs, you may click the link and find yourself re-engaged on the site.

This type of linking is also a smart way to increase the number of pages being indexed by Google. In that way, these additional internal links can benefit visitors and improve your SEO.

2. Display a Sitemap

If one or two links isn’t enough, you can go even further and include a sitemap on your custom error page. A sitemap gives visitors a concise summary of your site’s major sections, much like the table of contents in a book.

One website that uses this technique effectively is Starbucks:

Starbucks' error page with a sitemap.

When visitors encounter this error, instead of being lost and unsure what to do next, Starbucks has provided them with a guide to help them find what they’re looking for. This works especially well for complex sites with lots of moving parts.

Using this technique helps to keep visitors on your site, improving engagement. A sitemap gives them a choice of where they would like to go next, and can hopefully steer them towards the content that is most interesting to them.

3. Feature Product Links

Another approach to improving your error pages is to include links to popular products or services you offer. This enables visitors to navigate to what they are looking for, rather than giving up and clicking away.

The Land’s End clothing company has an error page that uses this technique:

Product links on an error page.

Links to the company’s various apparel departments are included on its error pages. By doing this, the site is giving visitors options. They can each choose a link that’s relevant to their needs, and they may even encounter new products they wouldn’t have otherwise considered.

Plus, product links are a great opportunity for e-commerce sites to improve their SEO. They provide yet another opportunity for internal links, and offer search engines more information about your site’s structure.

4. Add a Search Bar

If you prefer to keep things simple, you may opt to include a search bar on your custom error pages. By doing this, you are giving visitors the exact tool they need to find just about anything on your website.

A good example of a site that does this is GitHub:

A search bar on GitHub's error page.

A search bar gives visitors the power to simply look up whatever interests them. Rather than causing them to leave annoyed, you can hopefully provide the information they are looking for.

In addition, search bars are naturally engaging. They increase your odds of keeping visitors around for longer, which in turn can have a beneficial effect on your site’s optimization.


It’s important to keep your website as error-free as possible. When something does inevitably go wrong, however, customizing your error pages can help you retain user engagement and improve SEO.

Fortunately, .htaccess is a handy file you can use to redirect site visitors to the right place. When creating your custom error page via .htaccess, you can improve it by:

  1. Linking to top articles.
  2. Displaying a sitemap.
  3. Featuring product links.
  4. Adding a search bar.


Image credit: Stevepd.