2013-08-16 128 views
0

我已经在.htaccess文件中配置了缓存过期和gzip压缩,但是它没有按照yslow chrome扩展统计信息工作。Gzip压缩和缓存过期不起作用

这里是我的的.htaccess

# ---------------------------------------------------------------------- 
# 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> 

注:我使用的XAMPP

回答

2

这是我的第一篇文章在这里!

对于缓存过期:

你检查模块 “mod_expires.so” 已在Apache/conf目录/ httpd.conf中启用? 搜索行#LoadModule expires_module modules/mod_expires.so并删除“#”标志。之后,它应该工作。

对于gzip压缩:

我用 “mod_deflate模块” 启用压缩。我也使用“mod_mime”,“mod_setenvif”和“mod_headers”。检查每个在httpd.conf中启用。这种组合适用于我。

的.htaccess我压缩:

<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> 

更多信息here。我希望有所帮助。