.htaccess - 缓存来自 URL 的文件,例如 /files/large/6
我们有一个多站点 CMS,可以处理像这样的图像和其他文件。
我们如何使用 .htaccess 缓存 www.(或非 www.)variable-domain.com/files/* 中的图像和其他文件?
这会导致 500 错误。我删除了一些..这是我目前可以使用的内容(减去目录和内容部分 - 当包含它时它会抛出错误)。
#
# Force Browser Cache
#
<ifmodule mod_expires.c>
ExpiresActive On
<filesmatch "\.(jpg|gif|png|css|js)$">
ExpiresDefault "access plus 1 year"
</filesmatch>
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
<FilesMatch ".(js|css|pdf|txt)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
<Directory "/home/aiwebsystems/public_html/uploads">
<FilesMatch "\.(gif|jpg|png|js|css)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
</Directory>
</ifmodule>
我还需要包含其中的所有子目录...
感谢您的帮助!
We have a multisite CMS that handles images and other files like this..
How can we cache images and other files that are in www.(or non-www.)variable-domain.com/files/* with .htaccess?
This is causing a 500 error. I stripped out some.. here is what I have currently that works (minus the Directory and contents part - it throws the error when thats included).
#
# Force Browser Cache
#
<ifmodule mod_expires.c>
ExpiresActive On
<filesmatch "\.(jpg|gif|png|css|js)$">
ExpiresDefault "access plus 1 year"
</filesmatch>
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
<FilesMatch ".(js|css|pdf|txt)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
<Directory "/home/aiwebsystems/public_html/uploads">
<FilesMatch "\.(gif|jpg|png|js|css)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
</Directory>
</ifmodule>
I would need all subdirectories of this included too...
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Apache 的 mod_expires,
例如在 .htaccess 中放置:
A300 表示用户缓存的副本在访问后 300 秒过期。 (A86400 是访问后一天,A2592000 是访问后一个月)
如果您指的是服务器端缓存,那么您很幸运,因为操作系统最近使用“分页”算法进行缓存: http://en.wikipedia.org/wiki/Paging
Use Apache's mod_expires
e.g in your .htaccess put:
A300 meaning that the user cached copy expires 300 seconds after access. (A86400 is a day after access, A2592000 is a month after access)
If you mean server side caching, well then you are in luck as the operating system caches recently using a 'paging' algorithm: http://en.wikipedia.org/wiki/Paging
htaccess 中不允许使用
。只需创建一个新的 .htaccess 文件,其中包含过期内容,并将其放入“uploads”目录中。这将产生与您尝试达到的效果相同的效果
<Directory>
is not allowed in htaccess.Just create a new .htaccess file, with the expires stuff, and put it inside the 'uploads' directory. This will have the same effect you try to achief
由于它没有扩展,所以这些都不起作用。我最后更改了代码,现在效果很好,使用文件名而不是图像 ID 作为最后一个 URI 参数。
Being as it does not have an extension, none of this worked. I change the code in the end and it works great now, using the file name rather than the image ID as the last URI parameter.