edit htaccess files

How to edit htaccess files on WordPress for Custom Error Pages

Today we will learn How to edit htaccess files on WordPress for Custom Error Pages. Error messages are generally not considered good for search engine optimization (SEO). In fact, they are generally not positive about anything. However, no matter how carefully you maintain your site, you may encounter them from time to time.

When errors appear, there are ways you can limit the potential impact on your site’s search engine optimization (SEO). Perhaps the best way to do this is to redirect users to a custom error page using a .htaccess file.

The page can include links to popular articles and even a sitemap to help users navigate back to a working section of your site.

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

An introduction to the .htaccess files

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

You can think of the .htaccess file as the janitor of an apartment building (the folder or directory that contains it). When you open the door and tell the doorman (.htaccess) where you want to go, he will direct you to the building (directory) and the correct apartment unit (the file you asked for).

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

How to use .htaccess to redirect users to a custom error page

When a request is made to the web server and it is unable to respond, it sends an error message. If you do not specify any type of error handling, the server will probably display a generic message like this:

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

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

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

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

Here you can insert the HTML file for your custom error page. All you have to do is specify which document to use with the error, such as:

 ErrorDocument 404 /errors/not-found.html

In this post, “not-found.html” is your custom error page file You can create and insert similar files for other common errors, such as 400 Bad Requests and 403 Forbidden messages.

How to Improve SEO Using a Custom Error Page

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

1. Links to top articles

Adding internal links to your error pages allows users to go somewhere other than clicking away from your site You might be able to entice them with some of your other content, perhaps why they’re on your site in the first place.

For example, see this error page from Amazon:

edit htaccess file

Amazon piqued our interest with a picture of a dog and a link to meet Amazon’s dogs If you’re curious and you like dogs, you can click on the link and find yourself re-engaged on the site.

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

2. Display a Sitemap

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

One website that uses this strategy effectively is Starbucks:

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

Using this strategy helps to keep visitors to your site, and improve engagement. A sitemap gives them a choice of where they want to go next and hopefully leads them to the most interesting content.

3. Feature Product Links

Another method to improve 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 instead of giving up and clicking.

The Land’s End Clothing Company has an error page that uses this trick:

edit htaccess file

Links to the company’s various apparel categories are included on its error pages. By doing this, the site gives options to visitors. They can each choose a link relevant to their needs, and they may encounter new products they would not otherwise consider.

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

4. Add a search bar

If you prefer to keep things simple, you can choose to include a search bar in your custom error pages. By doing this, you’re giving visitors the right tools they need to find anything on your website.

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

edit htaccess file

A search bar gives visitors the ability to look for topics that interest them Instead of boring them, you can hopefully provide the information they’re looking for. Additionally, the search bar is naturally engaging. These increase the chances of your visitors staying longer, which can have a beneficial effect on your site’s optimization.

Conclusion

This is important to keep your website as error-free as possible. When things inevitably go wrong, however, customizing your error pages can help you maintain user engagement and improve SEO.

Fortunately, .htaccess is a simple file that you can use to redirect site visitors to the right place. When creating your custom error page via .htaccess, you can enhance it with:

  • Linking to top articles.
  • Displaying a sitemap.
  • Product links included.
  • Adding a search bar.
Scroll to Top