.htaccess Gzip压缩和缓存过期不工作
我在.htaccess文件中配置了缓存过期和gzip压缩,但根据yslow chrome扩展名统计,它不能工作 这是我的.htaccess.htaccess Gzip压缩和缓存过期不工作,.htaccess,xampp,gzip,cache-expiration,.htaccess,Xampp,Gzip,Cache Expiration,我在.htaccess文件中配置了缓存过期和gzip压缩,但根据yslow chrome扩展名统计,它不能工作 这是我的.htaccess # ---------------------------------------------------------------------- # Mod Rewrite # ---------------------------------------------------------------------- <IfModule mod_re
# ----------------------------------------------------------------------
# Mod Rewrite
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
# ----------------------------------------------------------------------
# gZip Compression
# ----------------------------------------------------------------------
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
# ----------------------------------------------------------------------
# Expires headers (for better cache control)
# ----------------------------------------------------------------------
<IfModule mod_expires.c>
ExpiresActive on
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Media: images, video, audio
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# CSS and JavaScript
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
</IfModule>
#----------------------------------------------------------------------
#修改
# ----------------------------------------------------------------------
选项-多视图
重新启动发动机
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
# ----------------------------------------------------------------------
#gZip压缩
# ----------------------------------------------------------------------
mod_gzip_on Yes
是的
mod|gzip|item|u include file.(html?| txt | css | js | php | pl)$
mod_gzip_item_包含处理程序^cgi脚本$
mod_gzip_项目包括mime^text/*
mod_gzip_item_包括mime^application/x-javascript*
mod_gzip_项_排除mime^image/*
mod_gzip_item_排除rspheader^内容编码:.*gzip*
# ----------------------------------------------------------------------
#Expires标头(用于更好的缓存控制)
# ----------------------------------------------------------------------
过期于
#您的文档是html
ExpiresByType text/html“访问加0秒”
#媒体:图像、视频、音频
ExpiresByType音频/ogg“访问加1个月”
ExpiresByType image/gif“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
ExpiresByType图像/png“访问加1个月”
按类型视频/mp4“访问加1个月”过期
按类型视频/ogg“访问加1个月”过期
过期按类型视频/webm“访问加1个月”
#CSS和JavaScript
ExpiresByType应用程序/javascript“访问加1年”
ExpiresByType文本/css“访问加1年”
注意:我正在使用Xampp这是我在这里的第一篇文章 对于缓存过期: 您是否检查了apache/conf/httpd.conf中是否启用了模块“mod_expires.so”? 搜索行
#LoadModule expires\u module modules/mod_expires.so
并删除“#”符号。在那之后,它应该会起作用
对于gzip压缩:
<IfModule mod_mime.c>
AddType application/x-javascript .js
AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
</IfModule>
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
我使用“mod_deflate”来启用压缩。我还使用“mod_mime”、“mod_setenvif”和“mod_headers”。检查httpd.conf中是否启用了每个选项。这种组合对我很有效
HTC访问我的压缩:
<IfModule mod_mime.c>
AddType application/x-javascript .js
AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
</IfModule>
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
AddType应用程序/x-javascript.js
AddType text/css.css
SetOutputFilter放气
setEnvifLocase请求_URI\(?:rar | zip)$无gzip不变
SetEnvIfNoCase请求_URI\(?:gif | jpg | png)$no gzip不变
setEnvifLocase请求_URI\(?:avi | mov | mp4)$无gzip不变
SetEnvIfNoCase请求\u URI\.mp3$no gzip不变
浏览器匹配^Mozilla/4 gzip纯文本/html
浏览器匹配^Mozilla/4\.0[678]无gzip
BrowserMatch\bMSIE!没有gzip!仅限gzip文本/html
标头附加变量用户代理env=!不要改变
更多信息。我希望这有帮助