1

这是我在 Apache httpd.conf 中为图像、JavaScript 和 CSS 启用缓存的方法

<IfModule mod_expires.c>
    <FilesMatch "\.(jpe?g|png|gif|js|css)">
        ExpiresActive On 
        ExpiresDefault "access plus 7 day"
        FileETag None
    </FilesMatch>
</IfModule>

我的问题是如何形成FilesMatch正则表达式否定断言以获得除图像、JavaScript 和 CSS 之外的所有内容的结果无缓存。下面不起作用。

# DISABLE ALL CACHING EXCEPT IMAGES,JAVASCRIPT AND CSS
<FilesMatch "\.?!(jpe?g|png|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 Note "CACHING IS DISABLED"
        Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </IfModule>
</FilesMatch>
4

1 回答 1

1

未经测试,但我认为这应该是(?<!\.(html|htm|js|css|json))$. 有关更多详细信息,请参阅我作为副本链接的问题。

于 2018-08-23T02:45:14.343 回答