简体   繁体   English

如何为jpeg图像设置默认响应头

[英]How to set default response headers for jpeg images

Ok so I have read a little about mod_headers however I have seen no definintive code to put in htaccess or anywhere else as for what to use in order to add the default response headers of Last-modified and Content-length to my jpeg images that other webites grab from me. 好的,所以我了解了一些有关mod_headers的内容,但是我没有看到明确的代码可以放入htaccess或其他任何地方,以用于将Last-modified和Content-length的默认响应标头添加到我的jpeg图像中的其他方法网站抢了我。 Without these they cant check whether or not to download the entire image again or not. 没有这些,他们将无法检查是否再次下载整个图像。 Any ideas? 有任何想法吗? Thanks! 谢谢!

"Content-Length" is set automatically. “内容长度”是自动设置的。 At first remove "Last-Modified" and append a new one. 首先,删除“ Last-Modified”并附加一个新的。 Works only in .htaccess if allowed. 如果允许,仅在.htaccess中工作。

<FilesMatch "\.(jpg|jpeg)$">
    Header unset Last-Modified
    Header append Last-Modified "Fri, 01 Mar 2012 12:00:00 GMT"
</FilesMatch>

Another option is to adapt a caching interval. 另一种选择是调整缓存间隔。

<IfModule mod_expires.c>
    ExpiresActive on
    # on access
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    # or on modification
    ExpiresByType image/jpg "modification plus 1 month"
    ExpiresByType image/jpeg "modification plus 1 month"
</IfModule>

I would prefer the caching on access combined with "Last-Modified". 我希望将访问缓存与“ Last-Modified”结合使用。

<FilesMatch "\.(jpg|jpeg)$">
    <IfModule mod_expires.c>
        ExpiresActive on
        ExpiresByType image/jpg "access plus 1 month"
        ExpiresByType image/jpeg "access plus 1 month"
    </IfModule>
    Header unset Last-Modified
    Header append Last-Modified "Fri, 01 Mar 2012 12:00:00 GMT"
</FilesMatch>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM