htaccess的重写规则

htaccess的重写规则

本文介绍了htaccess的重写规则,CSS,JS,图像文件prevent缓存。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经试过了?版本= 478459 的东西,以帮助prevent浏览器缓存一些文件如CSS,图片,JavaScript。因为我已经认识到它的只有这么乐于助人。简化版,似乎每次工作。例如,我要VPN插入之际,以任何理由改变工作参数,即使在文件的结尾像上面提到的文件将保留在缓存中,直到我清除它。我盘算参数可能不会坚持出于某种原因,因为我通过代理服务器上运行。但是,它开不总是似乎是这种情况无论是。

I've tried the ?ver=478459 stuff to help prevent browsers from caching some files like CSS, Images, JavaScript. And Since I've come to realize its only so helpful. Does't appear to work every time. Example, I have to VPN into work on occasion, and for whatever reason even when changing the parameters at the end of a file like above mentioned files will remain in the cache until I clear it. I'm figuring the parameter might not be sticking for some reason cause I am running through a proxy. But, it does't always seem to be the case either.

反正。我想弄清楚,如果有一种方法可以让我通过htaccess的提供rewrite_rule我的JS,CSS,IMG文件,若提供的网址是我不知道可以说

Anyway. I am trying to figure out, if there is a way I can through htaccess provide a rewrite_rule for my js, css, img files and if the URL provided is I dont know lets say

/scripts/jquery/__ver<version number>__/filename.js
/scripts/__ver<version number>__/filename2.js
/scripts/3.0.x/__ver<version number>__/filename2.js
/styles/jquery-ui/__ver<version number>__/filename.css
/styles/__ver<version number>__/filename2.css
/img/__ver<version number>__/something.png
/img/dir/dir/dir/__ver<version number>__/something-else.png

基本上是那里的重写规则正在寻找该 __版本&LT;版本号&GT; __ 专门和&LT;版本号&GT; 是一个3点的版本逻辑或者某种类型的MD5 ..或东西无论哪种方式基本上找 _ver * _

essentially where the rewrite rule is looking for this __ver<version number>__ specifically and <version number> is either a 3 dot versioning logic or a md5 of some sort.. or something either way basically looking for _ver*_

如果这个时候发现,重写规则将删除它和用户的路径,而不该部分

Where when this is found, the rewrite rule would remove it and user the path without that part

推荐答案

您可以明确地在.htaccess禁用缓存为选定的文件扩展名:

You can explicitly disable caching in .htaccess for chosen file extensions:

<FilesMatch "\.(png|jpe?g|gif|js|css)$">
   FileETag None
   <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Tue, 14 Jan 1975 01:00:00 GMT"
   </ifModule>
</FilesMatch>

这篇关于htaccess的重写规则,CSS,JS,图像文件prevent缓存。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 08:41