How to keep a log & track 404 errors in WordPress

Featured image for 404 errors article

When it comes to annoying website errors, not many are more irritating to your visitors than 404 error pages.

In most cases, your visitor will have clicked through from either a search result or an internal link placed on another page or post, only to find that there’s nothing there. For potential customers visiting your website for the first time, it doesn’t leave a good first impression.

But it hurts your WordPress site in other ways too. By keeping a log of 404 errors, not only will you improve your website’s user experience, but you’ll also be able to:

  • Quickly identify and fix broken links.
  • Improve your website’s search engine performance (SEO).
  • Better identify suspicious behaviour such as “fuzzer” scans or website infections.

What are 404s exactly?

From the perspective of a website visitor, when you see a 404 error, it could look something like this:

Example of 404 error

What this means is that the visitor’s web browser can successfully connect to the website server. However, the server can’t find the resource the visitor requested, such as a specific URL/page or file. Hence the web server responds back with a HTTP 404 error code.

What are HTTP status codes?

When you browse a website, your web browser communicates with the remote web server using the HTTP protocol. Whenever you request something from the web server, it responds back with a specific status or error code. Each error code means something specific.

For example; when a visitor requests a page that exists, your web server replies with HTTP status code 200, which means success page found. Your website visitors never see this displayed. Instead, they are simply presented with the resource or content requested.

But when someone tries to access a page on your website which doesn’t exist, your web server responds with an HTTP error code 404. This is an error that signifies an object has not been found. In the case of a missing post or page, a message relaying The 404 error will be displayed to visitors. Again, it could look something like this:

404 page not found error

HTTP status codes can be divided into five different categories:

  • 1xx informational – request received, continuing process
  • 2xx successful – request received, understood and accepted
  • 3xx redirection – further action is required to complete the request (typically some sort of redirection to another URL / resource)
  • 4xx client error – the request cannot be fulfilled or cannot be understood
  • 5xx server error – the request is valid however there was an error processing it

To learn more about all the different HTTP status codes and what each of which represents, view the complete list of HTTP status codes on Wikipedia.

Why do 404 errors occur on WordPress websites?

There are several reasons why there are 404 errors on your website. However, they are usually related to either one or a combination of the following things:

  • A WordPress page or post was deleted, and website visitors are still trying to access it.
    • Either via a link on another website, another page on your own website, or a search engine.
  • Another common problem, especially when there are multiple 404 errors, is a missing object or element on the page.
    • For example, let’s say you delete an image or a line of code in the footer of your website. Whenever a page on the website is loaded, the main bulk of the content may continue to load for visitors, but any missing resources will not. Generating multiple 404 errors on the back end.

Example of multiple 404 errors

  • Automated scanning programs also generate numerous 404 errors because they try to guess URLs. For instance, they will often request specific URL patterns to determine if the target website uses a specific system, for example:
    • /wp-admin/
    • /admin/
    • /portal/
    • /dashboard/

Using these programs in this way is called fuzzing. The fuzzing technique works by sending large volumes of random HTTP requests to a site in an attempt to uncover any bugs or security loopholes that could grant backdoor access. Thus, a massive spike in unexplained 404 errors is likely to be the result of a bad actor “fuzzing” your website. All to look for potential weaknesses.

Why 404 errors can hurt your site’s SEO performance

While 404 errors are mainly a cause for concern regarding your website’s user experience, they can negatively impact your search engine positions too.

First, it’s important to note that a 404 “not found” error doesn’t have a bearing on your website’s SEO performance in and of itself. However, the reasons behind that 404 error could be.

For instance, a visitor mistyping a URL is going to result in a 404 error. But it won’t have any negative impact on your SEO. By contrast, broken URLs that return 404 errors will prevent Google from crawling your site correctly, hurting your ranking positions.

That’s why it’s vital to keep a log of your 404 errors and fix them as soon as possible. So let’s walk you through how to do that.

How to keep a log of 404 errors

There are two principal methods for maintaining a log of 404 errors – through your web server log files or by using a plugin. Let’s start with the plugin option first.

Use the Redirection WordPress plugin

  1. Install and activate the Redirection plugin.
  2. Once activated, you will be able to view a log of all the 404 errors for your website.
  3. Once you have detected and logged your 404 errors, you can then use the redirection plugin to issue a 301 redirect for content or resources that have moved to new URL slugs.

Logged 404 errors

Use your web server log files

By default, a web server keeps a log of 404 errors in the access log file (refer to the list of log files every WordPress administrator should know about). Therefore by referring to the access log file you can see the 404 errors generated on your website.

If you host your own web server, you can also configure the web server to log more information about each request, such as the request itself, the referrer and much more.

What is the solution to 404 errors?

The solution depends on what the case is. For example, if the 404 error is being logged because an image that some pages on your website use has been deleted, then you should upload that image again.

However, if you have deleted old content you should set up a redirect. Redirects can be added to your website via the web host’s control panel, via the Redirection plugin we mentioned earlier, or you can manually add them to your website’s .htaccess file.

To add a single redirect for a page or post using the .htaccess file, add the following directive:

Redirect 301 /old-url https://yourdomain.com/new-url

Conclusion

Tracking and logging 404 “not found” errors is a vital task for any WordPress webmaster. These errors uncover broken links that are damaging from an SEO perspective and highlight missing or removed objects that you need to redirect to their new location.

An explosion of 404s could also point to an infection on your website (not common but possible) or indicate that someone is using an automated fuzzer program against it.

Whatever the reason for the 404 errors, you can easily keep a log and take the necessary remedial action with the Redirection plugin or simply refer to your web server access log files. For the rest and to know about everything that is happening on your website, there is the WordPress activity log.


Source link

X
X