2013-08-20 17 views
1

我輸入以下到我的.htaccess文件www.localmarketingus.com添加以下,以提高速度爲.htaccess

<ifModule mod_deflate.c> 
    <filesMatch "\.(css|js|x?html?|php|xml|html)$"> 
    SetOutputFilter DEFLATE 
    </filesMatch> 
</ifModule> 
# BEGIN Turn ETags Off 
<ifModule mod_headers.c> 
    Header unset Pragma 
    Header unset ETag 
</ifModule> 
FileETag None 
# END Turn ETags Off  

# BEGIN Compress text files 
<ifModule mod_deflate.c> 
    <filesMatch "\.(css|js|x?html?|php|xml|html)$"> 
    SetOutputFilter DEFLATE 
    </filesMatch> 
</ifModule> 
# END Compress text files 

# BEGIN Expire Headers 
<IfModule mod_expires.c> ExpiresActive On 
ExpiresByType image/jpg "access plus 1 month" 
ExpiresByType image/jpeg "access plus 1 month" 
ExpiresByType image/gif "access plus 1 month" 
ExpiresByType image/png "access plus 1 month" 
ExpiresByType text/css "access plus 1 month" 
ExpiresByType text/html "access plus 1 month" 
ExpiresByType application/pdf "access plus 1 month" 
ExpiresByType text/x-javascript "access plus 1 year" 
ExpiresByType application/javascript "access plus 1 month" 
ExpiresByType application/x-javascript "access plus 1 month" 
ExpiresByType application/x-shockwave-flash "access plus 1 month" 
ExpiresByType image/x-icon "access plus 1 year" 
ExpiresDefault "access plus 1 month" 
</IfModule> 
#END Expire headers 

#BEGIN Vary Accept Encoding 
<IfModule mod_headers.c> 
    <FilesMatch "\.(js|css|xml|gz)$"> 
    Header append Vary: Accept-Encoding 
    </FilesMatch> 
</IfModule> 
#END Vary Accept Encoding 

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

# BEGIN Cache-Control Headers 
<ifModule mod_headers.c> 
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$"> 
    Header set Cache-Control "max-age=2592000, public" 
    </filesMatch> 
    <filesMatch "\.(css)$"> 
    Header set Cache-Control "max-age=604800, public" 
    </filesMatch> 
    <filesMatch "\.(js)$"> 
    Header set Cache-Control "max-age=216000, private" 
    </filesMatch> 
    <filesMatch "\.(x?html?|php)$"> 
    Header set Cache-Control "max-age=600, private, must-revalidate" 
    </filesMatch> 
</ifModule> 
# END Cache-Control Headers 

# BEGIN Remove Last-Modified Header 
<ifModule mod_headers.c> 
    Header unset Last-Modified 
</ifModule> 
# END Remove Last-Modified Header 

然而,當我跑GTMetrix和PageSpeed Insights的它仍然說,我需要利用瀏覽器緩存並改變:接受編碼?

有沒有我在代碼中做錯了?

感謝,

回答

1

請補充一點:

#BEGIN Vary Accept Encoding 
<IfModule mod_headers.c> 
<FilesMatch "\.(js|css|xml|gz)$"> 
Header append Vary Accept-Encoding 
</FilesMatch> 
<FilesMatch "\.(ico|jpe?g|png|gif|swf)$"> 
Header set Cache-Control "public" 
</FilesMatch> 
<FilesMatch "\.(css)$"> 
Header set Cache-Control "public" 
</FilesMatch> 
<FilesMatch "\.(js)$"> 
Header set Cache-Control "private" 
</FilesMatch> 
<FilesMatch "\.(x?html?|php)$"> 
Header set Cache-Control "private, must-revalidate" 
</FilesMatch> 
</IfModule> 
#END Vary Accept Encoding  

相反的:

#BEGIN Vary Accept Encoding 
<IfModule mod_headers.c> 
<FilesMatch "\.(js|css|xml|gz)$"> 
Header append Vary: Accept-Encoding 
</FilesMatch> 
</IfModule> 
#END Vary Accept Encoding 

您可以在gtmetrix看到我在「指定打進100%檢查出我的網站Vary:Accept-Encoding header「test」。這是我的網站:http://www.fotoshooting.ro/

祝你好運!