在 HTTP 标头中设置到期日期或最长期限

Setting an expiry date or a maximum age in the HTTP headers(在 HTTP 标头中设置到期日期或最长期限)
本文介绍了在 HTTP 标头中设置到期日期或最长期限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了一个我指定的网站并将其提交给 Google 洞察 剪切和粘贴的示例

<IfModule mod_headers.c># 星期<FilesMatch ".(jpg|jpeg|png|gif|swf)$">标头集 Cache-Control "max-age=604800, public"</文件匹配></IfModule>

如果从 PHP 外壳交付材料,您可以使用 PHP 创建标头,在这种情况下,您可以参考此处概述的 HTTP 协议第 14.9 节缓存控制 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

我认为 .htaccess 在这两种方法中更容易.

I just finished a website that I designated and submitted it to google insights http://developers.google.com/speed/pagespeed/insights/ for performance reviews, and this is the result I got.

It says, I need to set expiry date or a maximum age in the the HTTP headers, but I don't know how it is possible to set expiry date for anything other than cookies/sessions.

解决方案

Generally that is done using the .htaccess file on your host. Here is an example cut and pasted from HTTP cache headers with .htaccess

<IfModule mod_headers.c>
# WEEK
<FilesMatch ".(jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</IfModule>

If delivering materials from a PHP shell you could use PHP to create the header in which case you would refer to the HTTP protocal outlined here section 14.9 Cache-Control http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

<?php
/* This file is a wrapper, */

header( 'Cache-Control: max-age=604800' );
/* now get and send images */
?>

I consider the .htaccess the easier of the two methods.

这篇关于在 HTTP 标头中设置到期日期或最长期限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)