的.htaccess缓存静态内容(除非修改)?缓存、静态、内容、htaccess

由网友(多情必自毙)分享简介:在想,这可能在.htaccess?Was wondering is this possible in .htaccess?我目前正在通过PHP缓存的.js,.css和所有的图像文件(并提供缓存只有在文件没有被通过检查filemtime()的改进型)。I'm currently caching .js, .css...

在想,这可能在.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>
阅读全文

相关推荐

最新文章