我的.htaccess代码错了吗?

时间:2017-02-13 19:22:29

标签: .htaccess cache-control

像Google PageSpeed这样的缓存检查网站会继续显示我的文件缓存仅2小时。我的htaccess文件有问题吗?规则的顺序?感谢

- 文件中的所有其他规则都有效。 (好吧,我确实有一些代码可以关闭那些似乎也不起作用的ETag)

- 我正在使用CloudFlare,但是支持告诉我cloudflare中没有任何内容影响缓存时间。

AddCharset UTF-8 .html 
RewriteEngine on
RewriteOptions inherit
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301,NC]

################ Require ending trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ %{REQUEST_URI}/ [R=301,L]

## 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 1 month"
</IfModule>
## EXPIRES CACHING ##


<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>


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

AddType application/x-httpd-php .html .htm

ErrorDocument 404 /404.php
ErrorDocument 410 /410.php

然后我有几个RewriteCond的

1 个答案:

答案 0 :(得分:0)

在apache配置文件中有一个vhost的mod_expires覆盖设置。