客户端请求图片:
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
我在 api/2.0/users.php 有一个脚本(是的,PATH_INFO 是打开的)
...
header('Content-Type: image/png');
$user = User::getUserWithID($filename);
header("Location: ".$user->getImageURL());
exit(0);
但 Apache 或 PHP 正试图表现得好像它了解我……但事实并非如此。它假设 PHP 脚本不可能想要用 image/png 响应,它会抛出一个 406 Not Acceptable
错误。
我能否成功配置 Apache/PHP 以响应此请求?
最佳答案
Can I successfully configure Apache/PHP to respond to this request?
是的。只需使用 MultiviewsMatch
指令告诉 Apache 它可以提供 .php
文件,无论它们的 MIME 类型是否与 Accept
header 兼容:
<Files "*.php">
MultiviewsMatch Any
</Files>
从文档看,效果如下:
You may finally allow
Any
extensions to match, even ifmod_mime
doesn't recognize the extension.
关于php - Apache 2 多 View 和图像/* 请求的 406 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19169337/