[英]Apache 2 multiviews and 406 error for image/* request
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) 我在api / 2.0 / users.php有一个脚本(是的,PATH_INFO已打开)
...
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. 但是Apache或PHP试图以自己了解我的方式行事……而事实并非如此。 It assumes a PHP script couldn't possibly want to respond with a image/png and it throws a
406 Not Acceptable
error. 它假定PHP脚本可能不想使用image / png进行响应,并且抛出
406 Not Acceptable
错误。
Can I successfully configure Apache/PHP to respond to this request? 我可以成功配置Apache / PHP来响应此请求吗?
Can I successfully configure Apache/PHP to respond to this request?
我可以成功配置Apache / PHP来响应此请求吗?
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: 只需使用
MultiviewsMatch
指令告诉Apache它可以提供.php
文件,而不管其MIME类型是否与Accept
标头兼容:
<Files "*.php">
MultiviewsMatch Any
</Files>
From the docs, the effect is as follows: 从文档来看,效果如下:
You may finally allow
Any
extensions to match, even ifmod_mime
doesn't recognize the extension.您最终可以允许
Any
扩展名匹配,即使mod_mime
无法识别扩展名也是如此。
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) 您需要在这种情况下禁用MultiView,或者使用扩展名告诉脚本的虚拟副本来告诉mod_negotiation它可以生成哪种模仿类型(不建议这样做)。
as-is, mod_negotiation has no way to probe for what types can be generated by users.php. 照原样,mod_negotiation无法探查users.php可以生成哪些类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.