The 404 Not Found Error is an HTTP response status code, which indicates that the requested resource could not be found. Like most HTTP response codes, the cause of a 404 Not Found Error can be challenging to track down and resolve.
This article will explore the 404 Not Found Error by examining what might cause this error. Later on, we'll provide a few tips to diagnose and debug your application's 404 error.
With that, let's get started!
Server- or Client-Side?
All HTTP response status codes in the 4xx category are client error responses. These types of messages contrast with errors in the 5xx category, such as the 502 Bad Gateway Error, which are server error responses.
That said, the appearance of a HTTP 404 error doesn't always mean the issue is client-related (web browser or device used to access the application). Sometimes, the root of the problem is server-side. Remember, the server is still the network object producing the 404 Not Found Error.
We'll explore some of the scenarios (and potential solutions) where the error results from the server and/or client issues in the following sections.
Start With a Thorough Application Backup
Make a backup of your application, database, etc. before trying to fix or change the system. Even better, if you have the capability, create a complete copy of the application onto a secondary staging server that isn't available to the public. This will give you a clean testing ground to test all potential fixes without threatening your live application.
After you've done that, it's time to start diagnosing and fixing your 404 error.
Diagnosing a 404 Not Found Error
A HTTP 404 error happens when a resource is unavailable. The client (web browser) received a message from the server (remote computer) that the specific resource (web page/URL) is unavailable.
Here are a few scenarios where this could happen:
- The client sent a proper request to the server, and the server successfully received that request, and the server could not find a valid resource at that particular location. This is typically due to an invalid URL specified by the client. This represents the majority of 404 Not Found Errors.
- Some web applications "fake" 404 Not Found Errors when requesting an invalid resource. The server returns a standard 200 OK response code, which means the resource loaded as expected, however, the server displayed a custom "404 page.” Such fake errors are typically referred to as soft 404 errors.
The provided URL could have been valid in the past, but the server has failed to provide a server-side redirect.
Troubleshooting on the Client-Side
The best way to start troubleshooting a 404 Not Found Error is to look for potential issues on the client side. Here are a few tips to try on the browser or device that's giving you problems.
Check the Requested URL
The most common cause of a 404 Not Found Error is inputting an incorrect URL. Domain names (e.g., airbrake.io) are case-insensitive, meaning that this mixed case link to AirBrAKe.IO works just as well as the standard, lowercase version of airbrake.io. However, path, query, or fragment portions that appear after the domain name are often case-sensitive unless the application/server configuration pre-processes all URLs as lowercase before execution.
For example, while airbrake.io can be upper, lower, or mixed case, a link to airbrake.io/ERROR-MONITORING/ (with BLOG in uppercase) is invalid, resulting in our good friend the 404 Not Found Error.
Of course, the lowercase version to https://www.airbrake.io/error-monitoring works just fine, as expected.
As you can see, a minor typo in part of the URL can easily result in an unexpected 404 Not Found Error.
Clear Relevant Cookies
As you may already be aware, HTTP cookies are tiny pieces of data stored on your local device. Websites and applications use these cookies to "remember" information about this particular browser and/or device.
Most modern web apps take advantage of cookies to store user and browser-specific data. By doing so, the app can identify the client and allow future visits to be faster and easier.
However, cookies can store just about any information. In many cases, web applications or services -- such as ad networks -- will use data retrieved from local cookies to redirect or handle incoming requests. An invalid or corrupted cookie can "confuse" the server as you try to access a resource that no longer exists. .
In most cases, you only need to concern yourself with cookies relevant to the website or application causing the problem. Cookies are stored based on the web application's domain name, so you can explicitly remove only those cookies that match the website domain (e.g., airbrake.io).
However, if you are unfamiliar with manually removing certain cookies, it's much easier and safer to clear all cookies at once.
Clearing cookies can be accomplished in different ways, depending on the browser you're using:
Log Out and Log In
If your application has some form of user authentication, the last client-side step to try is to log out and then log back in.
If you've recently cleared the browser cookies, this should usually log you out automatically the next time you try to load the page.
The application may have a problem with your previous session in some situations. As with other data, the session token (or session string) is stored locally on your device in the cookies and is transferred by the client to the server during every request. If the server doesn't recognize the session token sent by the client or something has gone wrong with the server that indicates that particular token is invalid, you may get a 404 error.
For most web applications, logging out and logging back in will force the local session token to be recreated.
Debugging Common Platforms
If you're running common software packages on the server that is responding with the 404 Not Found Error, you may want to start by looking into the stability and functionality of those platforms first.
The most common content management systems -- like WordPress, Joomla!, and Drupal -- are all typically well-tested out of the box. Still, once you start modifying the underlying extensions or PHP code, it's easy to cause an unforeseen issue that results in a HTTP 404 error.
Here are a few tips to help you troubleshoot some of these popular software platforms:
Rollback Recent Upgrades
If you recently updated the content management system itself before the 404 Not Found Error appeared, consider rolling back to the previous version you had installed when things were working fine.
Similarly, any extensions or modules you may have recently upgraded can cause server-side issues, so reverting to previous versions of those may also help.
For assistance with this task, simply Google "downgrade [PLATFORM_NAME]" and follow along. In some cases, however, certain CMSs don't provide a version downgrade capability. This is typically the case for the more popular platforms.
Uninstall New Extensions, Modules, or Plugins
The purpose of new extensions, modules, or plugins (they all mean the same thing) is to improve the capabilities and features of the platform beyond what it's capable of out of the box.
Check for Unexpected Database Changes
If you uninstall an extension, it may not completely remove all changes made by the extension. This is particularly true for many WordPress extensions, which are given carte blanche within the application. This can include full access rights to the database.
These extensions can modify database records that don't "belong" to the extension itself but are created and managed by other extensions (or even the base CMS itself). In those scenarios, the extension may not know how to revert alterations to database records, so it will ignore such things when uninstalled.
If you're convinced an extension is the likely culprit for the 404 Not Found Error, open the database and manually look through tables and records that were likely modified by the extension.
Troubleshooting on the Server-Side
If you aren't running a CMS application, here are some additional tips to help you troubleshoot your server.
Check Your Web Server Configuration
Most modern web servers provide one or more configuration files that allow you to adjust server behavior based on various circumstances easily.
For example, the server may be configured to reject requests to specific directories or URLs, resulting in a 404 Not Found Error.
Configuration options for each different type of web server can vary dramatically. We'll list a few popular web servers you can look through:
Look Through the Logs
Nearly every web application will keep some form of server-side logs. Application logs are typically the history of what the application did, including requested pages, connected servers, database results, etc.
Server logs are related to the actual hardware running the application. These logs will often provide details about the health and status of all connected services or the server itself.
Google "logs [PLATFORM_NAME]" if you're using a CMS, or "logs [PROGRAMMING_LANGUAGE]" and "logs [OPERATING_SYSTEM]" to get more information on finding the logs in question.
Validate Application Links
There are several tools you can use to ensure your application is not producing any 404 Not Found Errors.
For starters, you should register your site with the Google Search Console (if you haven't done so already). This tool gives you insight into what Google's web crawler bots have found while traversing your site.
Any issues will be displayed here for all your registered applications and can be an easy (and automatic) way to find invalid links or other site problems.
Need to check a particular resource or URL? Use the W3C Link Checker tool to check links for 404 errors.
Debug Your Application Code or Scripts
If all else fails, it may be that a problem in some custom code within your application is causing the issue. Try to diagnose where the issue may come from by manually debugging your application and parsing through application and server logs.
Ideally, make a copy of the entire application to a local development machine and perform a step-by-step debug process. This will allow you to recreate and view when and how the 404 error occurred.