SIGN IN / UP
    opened image


    Introduction


    While browsing various websites, users may encounter various errors. One of the most common is the 406 Not Acceptable error. HTTP 406 error code, known as "Not Acceptable", represents a server response indicating that it is unable to provide a response that matches the values specified in the client's request headers. This error usually occurs when the server cannot provide content that meets the criteria set by the client in the Accept header.

    This article will explore what the HTTP 406 error is, what factors cause it, and how to fix it if it occurs on your site.

     

    What is the HTTP 406 error?


    When web browsers request information from the server, they send an Accept header, which informs the server of the formats the browser can accept. If the server cannot send data in the format specified in the Accept header, it returns a 406 Not Acceptable error.

    This error can also be generated by the mod_security module. mod_security is a type of firewall program running on an Apache web server that scans for violations of predefined rules. If an action violates one of these rules, the server issues a 406 error.

     

     

    Causes of a 406 error on your site


    On sites hosted on your hosting account, the cause of the 406 error is usually a mod_security rule on the server. mod_security is a security module on the Apache web server, enabled by default on all hosting accounts. If a site, page, or feature violates one of these rules, the server may return a 406 Not Acceptable error.

     

    How to fix the 406 Not Acceptable error


    1. Review the error message


    When encountering an HTTP 406 error, the server usually includes a response message with additional information about the error. Start by reading this message to understand the specific problem.

     

    2. Check request headers

     

    The HTTP 406 error is related to the Accept header in the client's request. This header specifies the media types (content types) that the client can accept as a response. The server checks this header to determine whether it can provide content that meets the client's preferences. Make sure the Accept header is correctly set in your request.

     

    Example of an Accept header for accepting JSON:

     

    Accept: application/json

     

     

    Example of an Accept header for accepting both JSON and XML:

     

    Accept: application/json, application/xml

     

    In cPanel, to resolve the 406 error, you can fix this problem as follows:

     

    Disabling mod_security


    If you suspect that mod_security is the cause of the error, try temporarily disabling it for the specific domain. In cPanel, you can do this as follows:

     

    Log in to cPanel: Navigate to your website's control panel by entering your credentials.

    Find the "Security" section: Open the "ModSecurity" module.

     

     

     

    Disable mod_security for the domain: Find the desired domain in the list and disable the module by unchecking the box or selecting the corresponding option.

     

     

     

    Check your site: After disabling mod_security, try accessing the site again to see if the error is resolved.

     

    Important: Disabling mod_security reduces the security level of your site. Make sure you properly configure it before re-enabling.

     

     

    Configuring .htaccess in cPanel
    ​​​​​​​

    Open the .htaccess editor: Navigate to the "File Manager" in cPanel and open the .htaccess file located in your website's root directory.

     

     

    ​​​​​​​

     

    Configure directives: Make changes to the file to properly configure content negotiation. For example, add directives that help the server handle requests more efficiently:

     

    <IfModule mod_negotiation.c>
    Options -Multiviews
    </IfModule>

     


    Save your changes and test your site.

     

     

    3. Check content negotiation process


    Content negotiation is the process where the server selects the appropriate response format based on client preferences. If you're encountering a 406 error, it could be that the server is unable to provide content in the requested format. Check whether the server supports the media types specified in your Accept header.

     

    4. Use wildcards or more general types


    If the server supports multiple media types but you're still getting a 406 error, you can use wildcards or more general types in the Accept header. For example, you can use */* to indicate that you accept any media type:

     

    Accept: */*


    5. Check server configuration


    Ensure that the server is properly configured to handle content negotiation and can generate responses in the requested formats. Sometimes, improper server configuration can lead to 406 errors.

     

    6. Test different Accept header values


    Experiment with different Accept header values in your request to see if the server can provide content in any of the specified formats. This can help you identify which specific media type is causing the problem.

     

    7. Contact server administrator or API provider


    If you've exhausted all troubleshooting options and are still encountering an HTTP 406 error, it may be a server-side issue. Contact the server administrator or API provider to check whether there are any specific restrictions or issues causing the error.

     


    Following these steps can help resolve the HTTP 406 Not Acceptable error and ensure that your server properly handles content negotiation.