I've tried to find a solution for this myself but solutions to other 406 problems haven't helped me.
I have enabled PHP and the Apache web server on my Mac. I have found that if I pass a request (POST or GET) with the Accept: header set, then it fails with a 406 error:
$ curl -X GET -H "Accept: application/json" http://localhost/test/tester
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource /test/tester could not be found on this server.</p>
Available variants:
<ul>
<li><a href="tester.php">tester.php</a> , type application/x-httpd-php</li>
</ul>
</body></html>
However, if I exclude the "Accept: application/json" the request executes without error.
I tried adding this test/tester.var (in the same dir as test/tester.php):
URI: tester
Content-type: application/json
URI: tester.php
My intention was to direct Apache to handle request with "Accept: application/json" by executing tester.php. But it hasn't helped me (I also added 'AddHandler type-map .var' under 'IfModule mime_module' inside my httpd.conf file and restarted the server).
'mod_security' doesn't appear to be configured, but I added the following .htaccess to my test/ directory anyways:
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
These are solutions that I found on the net by none have worked for me.
Any ideas?
The primary way to address and fix a 406 error is by checking the source code for issues in the Accept-, Request-, and Response- headers. The easiest way to review Accept- and Response- headers is to open a webpage in your browser, right-click, and select Inspect.
The HyperText Transfer Protocol (HTTP) 406 Not Acceptable client error response code indicates that the server cannot produce a response matching the list of acceptable values defined in the request's proactive content negotiation headers, and that the server is unwilling to supply a default representation.
I finally figured out a fix! As I suspected, *mod_security* had nothing to do with my problem.
Here are the changes that I made to /etc/apache2/httpd.conf:
Added the following two lines to the "IfModule mime_module" section:
AddType application/x-httpd-php .php
MultiviewsMatch Handlers Filters
In my PHP source directory, I created a tester.var in the same directory as tester.php with the contents:
Content-type: application/json
URI: tester.php
It's all good now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With