标签: mod-expires

添加特定图像的过期标题

我看过的所有过期标题文章都或多或少地提供了以下解决方案:

ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
Run Code Online (Sandbox Code Playgroud)

但它对我没有意义,因为我知道我的哪些图像会改变,哪些不会改变,所以我希望能够为特定的图像文件添加特定的到期日期.我该怎么做?

.htaccess mod-expires

7
推荐指数
1
解决办法
1万
查看次数

添加没有mod_expires的expires头?

我知道我可以使用mod_expires添加expires头.但是,如果Apache服务器没有安装mod_expires并且我不想通过像PHP这样的脚本语言来访问文件,我该怎么办?

apache .htaccess mod-expires

7
推荐指数
1
解决办法
7008
查看次数

mod_expires为3个##状态代码发送Cache-Control标头

Apache正在为3 ##状态代码发送Cache-Control标头,例如302重定向.这导致Firefox(可能从Firefox 5开始)缓存302重定向 - 这导致我的某些页面无限重定向循环.

以下是我在我使用的设置httpd.conf:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
</IfModule>
Run Code Online (Sandbox Code Playgroud)

如果我删除了ExpiresDefault设置,问题就会消失,所以我确信这是造成问题的确切设置.如果我改变ExpiresDefault A600ExpiresByType text/html A600这个问题仍然存在.

我希望默认情况下让浏览器缓存我的内容,但这是一个交易破坏者.

是否有任何设置可以告诉Apache为3 ##状态代码发送不同的Cache-Control标头?

apache redirect cache-control mod-expires browser-cache

7
推荐指数
1
解决办法
1026
查看次数

PHP:标头过期无效

我的PHP代码:

$expires_date = date('D, j F Y H:i:s', strtotime('now + 10 years')) . ' GMT';           
header("Expires: $expires_date");
header('Content-type: text/javascript');

echo 'hello world';
Run Code Online (Sandbox Code Playgroud)

当我检查响应头时,我看到:

Expires:Thu, 01 Jan 1970 00:00:00 GMT

我究竟做错了什么?

更新:

只是在尝试,但似乎我甚至无法取消Expires via header_remove('Expires');.我仍然看到1970年的约会.

更新:

我的回复标题:

Cache-Control:private
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:74
Content-Type:text/javascript
Date:Wed, 17 Oct 2012 22:40:45 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Keep-Alive:timeout=5, max=98
Server:Apache/2.2.21 (Win32) PHP/5.3.9
Vary:Accept-Encoding
X-Powered-By:PHP/5.3.9
Run Code Online (Sandbox Code Playgroud)

.htaccess mod-expires response-headers expires-header

7
推荐指数
1
解决办法
2875
查看次数

mod_expires没有在JPEG图像上设置缓存控制头

我无法弄清楚为什么< 10 KB我正在处理的网站中的普通旧JPEG图像(大约十几个)不会采用缓存控制标头,而是强制输入..htaccess我正在使用的规则基于最新的HTML5 Boilerplate .htaccess文件(下面的相关部分).有什么奇怪的是,网站中有大量相同数量的PNG,除了其中两个外,缓存控制标头工作正常.

<IfModule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

...

# media: images, video, audio
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"

...

  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>

</IfModule>
Run Code Online (Sandbox Code Playgroud)

(省略号表示ExpiresByType删除了多余的规则部分)

我已经从我的/etc/apache2/apache2.conf文件直接到那里包含的几乎所有conf文件,并且找不到合理的解释.我已经摆弄,Pagesped和Chrome审核了几个小时的死亡,我仍然无能为力.

编辑:如下所述,.htaccess此网站的Web根目录中只有一个文件.JPEG正在通过mime类型image/jpeg正常,但缓存控制标头丢失,我无法弄清楚为什么.

apache .htaccess apache2 mod-expires http-headers

6
推荐指数
1
解决办法
7078
查看次数

将ExpiresDefault添加到.htaccess文件

我已更新我的.htaccess文件以包含以下内容:

<FilesMatch "\.(css|js)$">
ExpiresDefault "access plus 1 month"
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)

我试图告诉客户端所有的css和js都不会改变1个月,所以他们可以缓存他们的文件.

我有2个问题,

  1. 这会实现我想要的吗?
  2. 从添加我现在得到500错误,整个.htaccess文件如下:

    
    <FilesMatch "*\.(css|js)$">
    ExpiresDefault "access plus 1 month"
    </FilesMatch>
    # BEGIN Compression (DEFLATE)
    <IfModule mod_deflate.c>
    # Enable compression
    AddOutputFilterByType DEFLATE text/css text/javascript application/x-javascript text/html ``text/plain text/xml image/x-icon
    <IfModule mod_setenvif.c>
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    </IfModule>
    <IfModule mod_headers.c>
    # Make sure proxies deliver correct content
    Header append Vary User-Agent env=!dont-vary
    # Ensure proxies deliver compressed content correctly
    Header append Vary …
    Run Code Online (Sandbox Code Playgroud)

apache .htaccess web-hosting mod-expires

6
推荐指数
1
解决办法
8312
查看次数

使用Apache为文件系统中不存在的路径添加到期标头

出于CDN失效的目的,我需要在站点URL的路径元素中添加前缀.每当发布新版本的资产时,都会更改此信息.

然后使用mod_rewrite将URL重写为:http://example.com/cdn/20111030/images/image.jpghttp://example.com/images/image.jpg,这是资产实际所在的位置.

我想在响应中添加长期到期标题(至少3个月)(对于文件系统中实际不存在的第一个URL).有谁知道如何做到这一点?

apache mod-rewrite cdn mod-expires mod-headers

6
推荐指数
2
解决办法
6504
查看次数

标头在javascript文件上失效

我无法让JS文件上的过期标头正常工作..它可以正常工作,例如CSS文件!?

谁能告诉我我做错了什么?:(

htaccess的

ExpiresActive on
ExpiresDefault A0
ExpiresByType image/gif A29030400
ExpiresByType image/jpeg A29030400
ExpiresByType image/png A29030400
ExpiresByType text/css A29030400
ExpiresByType text/javascript A29030400
ExpiresByType application/x-javascript A29030400
Run Code Online (Sandbox Code Playgroud)

CSS文件上的标题

Cache-Control   max-age=29030400
Connection  Keep-Alive
Date    Sun, 14 Oct 2012 12:06:45 GMT
Etag    "be-4cbcf2ad48b40"
Expires Sun, 15 Sep 2013 12:06:45 GMT
Keep-Alive  timeout=5, max=97
Server  Apache/2.4.2 (Win64) PHP/5.4.3
Run Code Online (Sandbox Code Playgroud)

JS文件上的标题

Cache-Control   max-age=0
Connection  Keep-Alive
Date    Sun, 14 Oct 2012 12:06:45 GMT
Etag    "1ad-4cc00d069f493"
Expires Sun, 14 Oct 2012 12:06:45 GMT
Keep-Alive  timeout=5, max=99
Server  Apache/2.4.2 (Win64) …
Run Code Online (Sandbox Code Playgroud)

apache .htaccess header mod-expires

6
推荐指数
2
解决办法
1万
查看次数

Apache2 mod_expires 不起作用

我最近在支持 Apache2 的 VPS 上部署了一个网站,并且正在研究 YSlow 的性能改进建议。这些改进包括使用 mod_deflate 和 mod_expires,由于我有 root 访问权限,我可以直接编辑 Apache 配置文件。

mod_deflate 现在正在工作,但我遇到了 mod_expires 的问题,所以这是我所做的:

启用过期模块并重新启动服务器

a2enmod expires
service apache2 restart
Run Code Online (Sandbox Code Playgroud)

在 mods_enabled 下创建一个新文件“expires.conf”,其中包含以下内容:

<IfModule mod_expires.c>
  # Enable expirations
  ExpiresActive On

  # Default directive
  ExpiresDefault "access plus 1 month"

  # My favicon
  ExpiresByType image/x-icon "access plus 1 year"

  # Images
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/jpg "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"

  # CSS
  ExpiresByType …
Run Code Online (Sandbox Code Playgroud)

apache .htaccess mod-expires

6
推荐指数
1
解决办法
7731
查看次数

htaccess - 条件重写和到期

嘿!

/static我的Apache 2.x服务器webroot中有一个文件夹.如果请求匹配

/static/<somename like [\S-_]+>.(png|jpg|css|js)/\d{8,15}
Run Code Online (Sandbox Code Playgroud)

例如

/static/bg.jpg/1335455634
Run Code Online (Sandbox Code Playgroud)

我想要两件事:

  • url应改写为/static/bg.jpg(摆脱时间戳)
  • 它将成为一个永不过期('到期2030年,最大年龄= 290304000,公共缓存,...)

如果请求不匹配,请求及其标题应该正常,不重写.理想情况下,/ static/*之外的任何请求都不应受到影响(尽管«巧合的尾随时间段»应该很少......)

我对FilesMatch/RewriteCond只有麻烦,所以我宁愿不发布我的不良尝试...(在我的机器上启用了genereal中的重写,我确实拥有发送缓存相关头文件的权限)

Dankeschön!

apache .htaccess url-rewriting cache-control mod-expires

5
推荐指数
1
解决办法
1708
查看次数