1

The client is requesting an image:

GET /api/2.0/users/80.png HTTP/1.1
Host: learnwithecho.com
Proxy-Connection: keep-alive
Accept-Encoding: gzip, deflate
Accept: image/* <------------------------------ HERE'S THE IMPORTANT PART
Accept-Language: en-us
Connection: keep-alive
User-Agent: Echo/1.0.16.1 CFNetwork/672.0.2 Darwin/12.5.0

And I have a script at api/2.0/users.php (yes, PATH_INFO is on)

...
header('Content-Type: image/png');
$user = User::getUserWithID($filename);
header("Location: ".$user->getImageURL());
exit(0);

But Apache or PHP is trying to act like it knows me... and it don't. It assumes a PHP script couldn't possibly want to respond with a image/png and it throws a 406 Not Acceptable error.

Can I successfully configure Apache/PHP to respond to this request?

William Entriken
  • 37,208
  • 23
  • 149
  • 195
  • Related topics: http://stackoverflow.com/questions/12084283/406-server-error http://stackoverflow.com/questions/14251851/what-is-406-not-acceptable-response-in-http http://www.gerd-riesselmann.net/archives/2005/04/beware-of-apaches-multiviews – William Entriken Oct 03 '13 at 21:14
  • And http://stackoverflow.com/questions/14233146/406-error-not-acceptable-openwysiwyg-v1-4-7-while-image-selection – William Entriken Oct 03 '13 at 22:03

2 Answers2

3

Can I successfully configure Apache/PHP to respond to this request?

Yes. Just use the MultiviewsMatch directive to tell Apache that it can serve .php files regardless of whether their MIME type is compatible with the Accept header:

<Files "*.php">
    MultiviewsMatch Any
</Files>

From the docs, the effect is as follows:

You may finally allow Any extensions to match, even if mod_mime doesn't recognize the extension.

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
-1

You need to either disable MultiViews in this context or create dummy copies of your script with extensions that tell mod_negotiation what kinds of mimetypes it can generate (not really recommended)

as-is, mod_negotiation has no way to probe for what types can be generated by users.php.

covener
  • 17,402
  • 2
  • 31
  • 45