的.htaccess缓存静态内容(除非修改)? [英] .htaccess cache static content (unless modified)?

查看:143
本文介绍了的.htaccess缓存静态内容(除非修改)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在想,这可能在.htaccess?

Was wondering is this possible in .htaccess?

我目前正在通过PHP缓存的.js,.css和所有的图像文件(并提供缓存只有在文件没有被通过检查filemtime()的改进型)。

I'm currently caching .js, .css and all image files via PHP (and providing the cached only if the file has not been modified by checking the filemtime()).

但有人建议它是可以通过的.htaccess和更快,所以希望也许有人可以提供一些线索......我环顾四周,发现各种片段,但没有涵盖我后。

However someone suggested it's possible via .htaccess and much faster, so was hoping maybe someone can shed some light...I've looked around and found various snippets but none which cover what I'm after.

推荐答案

如果你已经有了的 mod_expires 的安装Apache服务器上,你可以把这样的事情在你的的.htaccess 文件。这个例子是面向PHP(实际上是从Drupal的7 的.htaccess 文件抓住了),而是应该作为一个很好的起点。

If you've got mod_expires installed on your apache server you can put something like this in your .htaccess file. This example is PHP orientated (actually grabbed from the Drupal 7 .htaccess file) but should serve as a good starting point.

FileETag MTime Size
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

这篇关于的.htaccess缓存静态内容(除非修改)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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