对于我的网站,除 index.html 文件之外,所有文件都被缓存。
对于.htaccess,我有:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R=301,L]
DirectoryIndex /index.html
AddType text/html .html
AddOutputFilter INCLUDES .html
ErrorDocument 404 https://www.mywebsite.com/
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
<Files 403.shtml>
order allow,deny
allow from all
</Files>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 year"
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/html "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/octet-stream "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
<IfModule mod_headers.c>
Header unset ETag
Header append Cache-Control "public, no-transform"
Header set X-UA-Compatible "IE=Edge,chrome=1"
# mod_headers can't match by content-type, but we don't want to send this header on *everything*...
<FilesMatch "\.(js|css|gif|png|jpe?g|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|oex|xpi|safariextz|vcf)$" >
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
</IfModule>
FileETag None
root 的响应头:
HTTP/1.1 200 OK
Date: Tue, 10 Mar 2015 21:11:03 GMT
Server: Apache/2.4.12 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 mod_fcgid/2.3.10-dev
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Cache-Control: max-age=31536000, public, no-transform
Expires: Wed, 09 Mar 2016 21:11:03 GMT
X-UA-Compatible: IE=Edge,chrome=1
Keep-Alive: timeout=5
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
来自所有其他文件的示例响应:
Accept-Ranges:bytes
Cache-Control:max-age=31536000, public, no-transform
Connection:Keep-Alive
Content-Encoding:gzip
Content-Type:text/css
Date:Tue, 10 Mar 2015 21:20:49 GMT
Expires:Wed, 09 Mar 2016 21:20:49 GMT
Keep-Alive:timeout=5
Last-Modified:Mon, 13 Oct 2014 01:18:29 GMT
Server:Apache/2.4.12 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 mod_fcgid/2.3.10-dev
Transfer-Encoding:chunked
Vary:Accept-Encoding
我能看到的唯一区别是Last-Modified
根文件中缺少。这是问题所在吗?如何将其添加到 htaccess 中?
如何才能像所有其他文件一样缓存主网站文件?
答案1
尝试通过注释掉以下行来禁用 HTML 文件中的服务器端包含,然后重新启动 Apache 以查看是否是导致此问题的原因。
AddOutputFilter INCLUDES .html