htaccess如果URL包含字符串,则禁用缓存? [英] htaccess Disable cache if URL contains string?

查看:96
本文介绍了htaccess如果URL包含字符串,则禁用缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果URL包含字符串",是否可以向htaccess添加例外? 像这样:

Can I add exception to htaccess if URL contains "string"? Sth like:

<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>

推荐答案

您可能可以使用FilesMatch指令,该指令可能对您有用.但是,它在QUERY_STRING中与字符串"不匹配.

You can probably use FilesMatch directive which might work for you. It won't match "string" in QUERY_STRING though.

还要确保FilesMatch指令位于较早的缓存设置之后.

Also make sure FilesMatch directive comes after earlier cache settings.

<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>

这篇关于htaccess如果URL包含字符串,则禁用缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆