htaccess Disable cache if URL contains string?

2019-09-09 06:49发布

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

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

? My caching mod:

<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条回答
小情绪 Triste *
2楼-- · 2019-09-09 07:06

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

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>
查看更多
登录 后发表回答