利用浏览器缓存 - 修改.htaccess文件时出现内部服务器错误

时间:2013-10-01 17:08:37

标签: apache .htaccess mod-expires

我正在努力加快我的网站速度。在Google PageSpeed Insights上我有86分,但我对Leverage browser caching有疑问。在recomendation中,我发现了这段.htaccess代码:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/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 2 days"
</IfModule>
## EXPIRES CACHING ##

但是当我将其插入我的.htaccess文件时,我会收到内部服务器错误(500)。

我的工作.htaccess代码就像这样:

AddHandler x-httpd-php53 .php 

RewriteEngine On
RewriteBase /
RewriteRule ^typo3$ - [L]
RewriteRule ^typo3/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php

# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4         gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE             !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我认为你应该启用模块&#34; mod_expires&#34;在服务器上: 使用ubuntu服务器类型:

a2enmod到期

/etc/init.d/apache2 restart