php minify - 浏览器重写的URL缓存

时间:2014-11-01 12:31:27

标签: php apache .htaccess mod-rewrite minify

我正在尝试使用php minify为CSS / JS创建重写的URL。在tools.pingdom我收到了这条消息: 以下可缓存资源的生命周期较短。为以下资源指定将来至少一周的到期时间:

http://www.xxx.xx/assets/minify/css-combined.css http://www.xxx.xx/assets/minify/js-combined.js

在根目录中我有.htaccess包含expires和标题规则:

<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault      "access plus 1 month"
# cache.appcache needs re-requests 
# in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 1 month"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"

# RSS feed
ExpiresByType application/rss+xml "access plus 1 hour"

# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"

# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"

# HTC files  (css3pie)
ExpiresByType text/x-component "access plus 1 month"

# Webfonts
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
ExpiresByType application/x-font-woff   "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"

<IfModule mod_headers.c>
    Header append Cache-Control "public"
    Header append Vary User-Agent
    <FilesMatch "\.(js|css|xml|gz|woff)$">
        Header append Vary: Accept-Encoding
    </FilesMatch>
</IfModule>

在minify的文件夹中有以下.htaccess规则:

RewriteEngine on 

RewriteRule ^(.*).js$ index.php?g=$1
RewriteRule ^(.*).css$ index.php?g=$1
你能帮帮我吗?我做错了什么?

谢谢=)

祝你好运, Russianroot

1 个答案:

答案 0 :(得分:0)

关闭IfModule可能会解决您的问题

<IfModule mod_expires.c>

我为你修改了

<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault      "access plus 1 month"
# cache.appcache needs re-requests 
# in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 1 month"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"

# RSS feed
ExpiresByType application/rss+xml "access plus 1 hour"

# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"

# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"

# HTC files  (css3pie)
ExpiresByType text/x-component "access plus 1 month"

# Webfonts
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
ExpiresByType application/x-font-woff   "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
    Header append Cache-Control "public"
    Header append Vary User-Agent
    <FilesMatch "\.(js|css|xml|gz|woff)$">
        Header append Vary: Accept-Encoding
    </FilesMatch>
</IfModule>