Apache 406 Not Acceptable when specifying Accept: header
apache, php
Solution
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:
- Enabled type maps in by uncommenting "AddHandler type-map var" line in the "IfModule mime_module" section.
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.
Problem
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?