HTTP标头后mod_rewrite的JPG文件 [英] HTTP headers for jpg files after mod_rewrite
问题描述
我使用Apache的的mod_rewrite
来我的网站根目录外的路由请求JPG文件到一个目录。
I'm using Apache's mod_rewrite
to route requests for JPG files to a directory outside my web root.
它通常一直很好,但也有不显示一些图片。后来我意识到,当我使用PHP的 get_headers()
功能对我的形象的网址,他们都返回结果的Content-Type:text / html的;字符集= UTF-8
而不是正确的图像/ JPEG
头类型。
It generally has been fine, but there are a few images that do not display. I then realized that when I use PHP's get_headers()
function on my image URLs, they are all returning
Content-Type: text/html; charset=UTF-8
instead of the proper image/jpeg
header types.
我已经尝试明确地设置内容类型:图像/ JPEG
头静静的,没有我的图片返回正确的标题 - 虽然大多数人正常显示,但我M不知道为什么。
I have tried explicitly setting the Content-Type: image/jpeg
header and still, none of my images return the correct headers - although most do display correctly, but I'm not sure why.
我怎样才能保证一个JPG文件通过的mod_rewrite
?
How can I assure a JPG file is sent with the correct header when redirecting via mod_rewrite
?
推荐答案
这是你能做些什么。创建一个PHP文件,将得到正确的文件,并通过
This is what you could do. Create a PHP file that will get the right file and passes it through
<?php
$sImage = 'imagename.jpg';
header("Content-Type: image/jpeg");
header("Content-Length: " .(string)(filesize($sImage)) );
echo file_get_contents($sImage);
或
<?php
$sImage = 'imagename.jpg';
$rFP = fopen($sImage, 'rb');
header("Content-Type: image/jpeg");
header("Content-Length: " .(string)(filesize($sImage)) );
fpassthru($rFP);
exit;
这篇关于HTTP标头后mod_rewrite的JPG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!