Apache 2 多视图和图像/* 请求的 406 错误 [英] Apache 2 multiviews and 406 error for image/* request

查看:15
本文介绍了Apache 2 多视图和图像/* 请求的 406 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端正在请求图像:

GET/api/2.0/users/80.png HTTP/1.1主持人:learnwithecho.com代理连接:保持活动接受编码:gzip、deflate接受: image/* <------------------------------ 这是重要的部分接受语言:en-us连接:保持连接用户代理: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("位置:".$user->getImageURL());退出(0);

但是 Apache 或 PHP 试图表现得好像它了解我……但它并不了解.它假设 PHP 脚本不可能想用图像/png 响应,并抛出 406 Not Acceptable 错误.

我可以成功配置 Apache/PHP 来响应这个请求吗?

解决方案

我可以成功配置 Apache/PHP 来响应这个请求吗?

是的.只需使用 MultiviewsMatch 指令即可告诉 Apache 它可以提供 .php 文件,而不管它们的 MIME 类型是否与 Accept 标头兼容:

<文件*.php">多视图匹配任何</文件>

从文档来看,效果如下:

<块引用>

您最终可以允许 Any 扩展名匹配,即使 mod_mime 不识别该扩展名.

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?

解决方案

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.

这篇关于Apache 2 多视图和图像/* 请求的 406 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆