Cloud Service >> Knowledgebase >> Cloud Server >> What is HTTP Error Code 406? A Clear Explanation
submit query

Cut Hosting Costs! Submit Query Today!

What is HTTP Error Code 406? A Clear Explanation

When managing a website, whether hosted on a colocation server or any other hosting environment, encountering errors is common. One such error is the HTTP 406 error code, also known as "Not Acceptable." This error can leave users frustrated and puzzled, especially if they don’t know what it means. In this guide, we’ll break down what HTTP Error Code 406 is, why it happens, and how to fix it—so you can keep your website running smoothly.

What is HTTP Error Code 406?

HTTP Error Code 406 is part of the HTTP status codes that servers use to communicate with browsers. A 406 error occurs when the server is unable to deliver the content in a format that’s acceptable to the client (usually the browser).

Here’s what happens: When a user visits your website, their browser sends a request to the server asking for the content. This request includes the formats or MIME types (like text/html, application/json) the browser can accept. If the server can’t deliver the content in any of the requested formats, it sends back a 406 error.

Simply put, the server is telling the browser that it cannot provide the content in an acceptable format.

Why Does HTTP Error Code 406 Occur?

There are a few common reasons for the 406 "Not Acceptable" error. These reasons typically stem from server settings or content type issues:

MIME Type Mismatch: Your server may be serving content in a format that the client cannot accept. For example, the browser might request text/html, but the server is only able to provide application/json.

Improper Configuration: Sometimes, incorrect settings on the server can lead to this error. If a website is hosted on a shared hosting or colocation server, specific configurations related to content negotiation (how the server decides what format to serve) could be misconfigured.

Mod_security or Other Security Filters: On certain servers, particularly those using security modules like mod_security, specific filters may block content based on the MIME type. This can trigger a 406 error if the server’s security settings are too restrictive.

Client-Side Issues: In some rare cases, the problem could be on the user's side, such as a misconfigured browser or plugin that’s restricting the types of content it can accept.

How to Fix HTTP Error Code 406

Now that we know what causes the 406 error, let's dive into how you can resolve it. Whether you're managing your own hosting environment or using a colocation server, these steps will guide you through the fix.

1. Check the Server Logs

The first step in troubleshooting any server issue is to check the error logs. Most hosting environments, including shared and colocation servers, provide access to server logs. These logs can give you details about what content type the server tried to serve and why it was rejected.

How to do it:

Access your server’s control panel (like cPanel) or use an SSH connection to view the error logs.

Look for entries around the time the 406 error occurred. Pay close attention to the MIME types mentioned.

2. Review and Modify .htaccess File

If you're hosting on an Apache server (which many hosting and colocation servers use), your .htaccess file plays a significant role in how content is served. Sometimes, incorrect rules in the .htaccess file could cause content negotiation issues, leading to the 406 error.

How to do it:

Access the root directory of your website via FTP or your cloud hosting control panel.

Open the .htaccess file and review any directives related to content types or security filters.

If you’re unsure which part is causing the issue, comment out the recent changes you’ve made or add the following directive to disable content negotiation temporarily:
apache

SetEnvIf Accept application/json no-gzip dont-vary

Save the changes and test your website again.

3. Adjust Server-Side Security Filters

If you're using a security module like mod_security on your server, it’s possible that these settings are causing the 406 error. Mod_security is a popular firewall that protects servers from malicious traffic, but sometimes its rules can be too strict, blocking legitimate requests.

How to do it:

If you’re using shared hosting, contact your hosting provider to adjust the mod_security settings for you.

For colocation or dedicated servers, you can tweak these settings yourself by modifying the mod_security rules in your configuration files.

4. Review Accept Headers Sent by the Client

The client (or browser) sends an “Accept” header when requesting content from the server. If these headers are misconfigured, it could lead to a 406 error.

How to do it:

Use developer tools (in browsers like Chrome or Firefox) to inspect the request headers sent by the client.

If you see any unusual or overly restrictive MIME types in the “Accept” header, recommend that the user disable any browser extensions or plugins that might be interfering.

5. Content-Type Adjustments

If the server is delivering content in the wrong format (for example, JSON when HTML is expected), you may need to adjust the content negotiation settings on your server.

How to do it:

Ensure that your server is correctly configured to serve the content in the formats most browsers expect. On most servers, you can do this through configuration files like httpd.conf or directly within your web application’s settings.

Preventing HTTP Error Code 406 in the Future

While fixing a 406 error is usually straightforward, preventing it from happening again is key to keeping your site running smoothly, whether you're using shared hosting or colocation servers.

Regularly review server logs: Check logs for any abnormal patterns in how content is being served.

Ensure correct MIME types: Make sure that your server can serve the content in the formats most browsers will request.

Test your website: Regularly test your website across different browsers and devices to ensure compatibility.

Conclusion

HTTP Error Code 406 is a frustrating error, but it can be resolved by identifying the cause—typically related to MIME types, server security settings, or content negotiation. Whether you’re using shared hosting, dedicated hosting, or a colocation server, keeping an eye on server logs and understanding how content is served is key to preventing this error in the future.

By following the troubleshooting steps outlined in this guide, you'll be able to resolve the issue quickly and ensure that your website continues to run smoothly for all visitors.

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!