2013-01-19 100 views
0

我試圖通過.htaccess規則在我的VPS服務器上設置緩存。我確定安裝了mod_expires和mime類型檢測,但是當我通過gtmetrix運行我的網站時,它顯示我沒有啓用緩存。以下是我的.htaccess規則:已安裝Apache模塊但htaccess緩存不起作用

# Expire headers 
<ifModule mod_expires.c> 
    ExpiresActive On 
    ExpiresDefault "access plus 1 seconds" 
    ExpiresByType image/x-icon "access plus 2592000 seconds" 
    ExpiresByType image/jpeg "access plus 2592000 seconds" 
    ExpiresByType image/png "access plus 2592000 seconds" 
    ExpiresByType image/gif "access plus 2592000 seconds" 
    ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" 
    ExpiresByType text/css "access plus 604800 seconds" 
    ExpiresByType text/javascript "access plus 216000 seconds" 
    ExpiresByType application/javascript "access plus 216000 seconds" 
    ExpiresByType application/x-javascript "access plus 216000 seconds" 
    ExpiresByType text/html "access plus 600 seconds" 
    ExpiresByType application/xhtml+xml "access plus 600 seconds" 
</ifModule> 

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

# Turn ETags Off 
<ifModule mod_headers.c> 
    Header unset ETag 
</ifModule> 
FileETag None 

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

回答

0

嘗試在FilesMatch塊中添加Last-Modifed。 類似這樣的:

<FilesMatch "\.(jpg|jpeg|png|gif|js|css|ico)$"> 
    ExpiresDefault "access plus 10 years" 
    Header set Cache-Control "public" 
    Header set Last-Modified "Mon, 31 Aug 2009 00:00:00 GMT" 
    Header unset ETag 
    Header append Cache-Control "max-age=604800, public" 
</FilesMatch > 
+0

我加了它,仍然沒有運氣。 – user715564

+0

確保mod_headers.c已啓用?嘗試刪除塊。在這種情況下,如果模塊mod_headers.c未啓用,您將收到錯誤消息。 – ivi

+0

好吧,我刪除了mod_headers.c塊並沒有得到一個錯誤。 – user715564

相關問題