What Is A 404 Error?

9 minutes read

A 404 error is a common error message that indicates a webpage cannot be found on the server. This can happen when a user types in a URL incorrectly, clicks on a broken link, or when a website has been moved or deleted. The number 404 is part of the HTTP status codes, and it typically appears as "404 Not Found" on a blank white page. This error can be frustrating for users, but it is important for web developers to address and fix so that users can access the correct information on a website.

Best SEO Books to Read in November 2024

1
SEO Workbook: Search Engine Optimization Success in Seven Steps (2024 Marketing - Social Media, SEO, & Online Ads Books)

Rating is 5 out of 5

SEO Workbook: Search Engine Optimization Success in Seven Steps (2024 Marketing - Social Media, SEO, & Online Ads Books)

2
The Art of SEO: Mastering Search Engine Optimization

Rating is 4.9 out of 5

The Art of SEO: Mastering Search Engine Optimization

3
Honest SEO: Demystifying the Google Algorithm To Help You Get More Traffic and Revenue

Rating is 4.8 out of 5

Honest SEO: Demystifying the Google Algorithm To Help You Get More Traffic and Revenue

4
Search Engine Optimization All-in-One For Dummies (For Dummies (Business & Personal Finance))

Rating is 4.7 out of 5

Search Engine Optimization All-in-One For Dummies (For Dummies (Business & Personal Finance))

5
SEO For Dummies, 7th Edition (For Dummies (Computer/Tech))

Rating is 4.6 out of 5

SEO For Dummies, 7th Edition (For Dummies (Computer/Tech))

6
3 Months to No.1: The "No-Nonsense" SEO Playbook for Getting Your Website Found on Google

Rating is 4.5 out of 5

3 Months to No.1: The "No-Nonsense" SEO Playbook for Getting Your Website Found on Google

7
The SEO Entrepreneur: Start a Successful SEO Business and Turn Your Entrepreneurial Dreams Into Reality

Rating is 4.4 out of 5

The SEO Entrepreneur: Start a Successful SEO Business and Turn Your Entrepreneurial Dreams Into Reality


How to track 404 errors on a website using Google Analytics?

To track 404 errors on a website using Google Analytics, you can follow these steps:

  1. Sign in to your Google Analytics account and navigate to the website you want to track 404 errors for.
  2. Go to the "Admin" section and select the "View" where you want to track 404 errors.
  3. Click on "View Settings" and toggle the "Enable Ecommerce" setting to "On" if it is not already enabled.
  4. Create a custom 404 error tracking page on your website. This page should have a unique URL that is not used elsewhere on your site.
  5. Once the custom 404 error tracking page is created, go to "Behavior" > "Site Content" > "All Pages" in Google Analytics.
  6. Use the search bar to filter for the URL of the custom 404 error tracking page.
  7. Click on the URL of the custom 404 error tracking page to view the data associated with it.
  8. You will now be able to see information about the 404 errors, such as the number of times users have landed on the page and where they are coming from.


By following these steps, you can easily track 404 errors on your website using Google Analytics and take necessary actions to fix them.


How to monitor 404 errors using server logs?

To monitor 404 errors using server logs, follow these steps:

  1. Access your server log files: Log into your server where your website is hosted and locate the log files. The location of log files may vary depending on your server configuration. Common locations include /var/log/apache/access.log for Apache servers and /var/log/nginx/access.log for Nginx servers.
  2. Search for 404 errors: Use a command-line tool such as grep to search for occurrences of the HTTP status code 404 in the log files. For example, you can use the following command to search for 404 errors in an Apache log file:
1
grep "404" /var/log/apache/access.log


  1. Analyze the results: Review the output of the command to see the URLs that resulted in 404 errors. Look for patterns or common sources of the errors, such as broken links or mistyped URLs.
  2. Set up alerts or notifications: To proactively monitor 404 errors, you can set up alerts or notifications for when a certain threshold of errors is reached. You can use monitoring tools or scripts to continuously monitor the log files for 404 errors and send alerts when necessary.
  3. Take corrective action: Once you identify the sources of 404 errors, take corrective action to fix broken links, update URLs, or make any necessary changes to prevent further errors from occurring.


By monitoring 404 errors using server logs, you can identify and address issues that may be impacting the user experience on your website.


What is the difference between a hard 404 error and a soft 404 error?

A hard 404 error occurs when a web server returns a response code of 404, indicating that the requested page could not be found. This usually happens when a page has been removed or the URL is incorrect.


A soft 404 error, on the other hand, occurs when a web server returns a response code of 200 (indicating that the page was found) even though the content of the page suggests that it does not exist or is not relevant to the user's search query. This can happen when a website redirects users to a generic error page or a page with little to no useful information.


What is the best practice for handling 404 errors in JavaScript?

One common best practice for handling 404 errors in JavaScript is to use the Fetch API to make a request to a server and handle any errors that occur. Here is an example of how you can handle a 404 error using the Fetch API:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
fetch('https://example.com/api/data')
  .then(response => {
    if (!response.ok) {
      throw new Error('Failed to fetch data');
    }
    return response.json();
  })
  .then(data => {
    // Handle the data
  })
  .catch(error => {
    if (error.message === 'Failed to fetch data') {
      console.error('404 error: Data not found');
    } else {
      console.error('An error occurred: ', error);
    }
  });


In this example, we make a request to the server using the Fetch API. If the response is not OK (i.e., the status code is not in the range 200-299), we throw an error with a custom message. We then handle the error in the catch block and check if the error message matches the one we specified for a 404 error. We can then log a specific message for the 404 error and handle other errors separately.


Overall, the best practice for handling 404 errors in JavaScript is to use the Fetch API to make requests and handle any errors that occur in a clear and structured way.

Facebook Twitter LinkedIn Whatsapp Pocket

Related Posts:

To set up a custom error page on web hosting, you need to follow these steps:Identify the type of error: Determine the HTTP error status code for which you want to set up a custom page. Common error codes include 404 (page not found), 500 (internal server erro...
Are you seeing ‘Your connection is just not non-public’ error in your WordPress web site? That is the error message you’ll see on Google Chrome. The identical error will probably be displayed on all trendy browsers with barely totally different messages, and ...
Are you seeing the ‘Error establishing a database connection’ discover in your WordPress web site? It’s a deadly error that makes your WordPress web site inaccessible to the customers. This error happens when WordPress is unable to make a connection to the da...
Mail servers have an SMTP authentication characteristic enabled in them, to validate customers who attempt to ship mails by way of that server. The ‘SMTP AUTH’ error often occurs when customers attempt to ship mails with out correctly authenticating their mail...