htaccess如果URL包含字符串,则禁用缓存?

时间:2013-12-14 10:01:31

标签: apache .htaccess caching mod-expires

如果网址包含"字符串"我可以向htaccess添加例外吗? 就像:

<if URL contains "string">
 ExpiresDefault "access plus 1 days"
</ifModule>

? 我的缓存模式:

<ifModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpg "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType image/vnd.microsoft.icon "access plus 1 months"
ExpiresByType image/x-icon "access plus 1 months"
ExpiresByType image/ico "access plus 1 months"
ExpiresByType application/javascript "now plus 1 months"
ExpiresByType application/x-javascript "now plus 1 months"
ExpiresByType text/javascript "now plus 1 months"
ExpiresByType text/css "now plus 1 months"
ExpiresDefault "access plus 1 days"
</IfModule>

1 个答案:

答案 0 :(得分:1)

您可以使用可能适合您的FilesMatch指令。它虽然与QUERY_STRING中的“string”不匹配。

还要确保在早期缓存设置之后出现FilesMatch指令。

<ifModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpg "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType image/vnd.microsoft.icon "access plus 1 months"
ExpiresByType image/x-icon "access plus 1 months"
ExpiresByType image/ico "access plus 1 months"
ExpiresByType application/javascript "now plus 1 months"
ExpiresByType application/x-javascript "now plus 1 months"
ExpiresByType text/javascript "now plus 1 months"
ExpiresByType text/css "now plus 1 months"
ExpiresDefault "access plus 1 days"
</IfModule>

<FilesMatch "string">
   ExpiresDefault "access plus 1 days"
<<FilesMatch>