apache 防盗链,缓存,不缓存的配置

来源:互联网 发布:单片机技术论坛 编辑:程序博客网 时间:2024/05/29 16:38
RewriteEngine onRewriteCond %{REQUEST_FILENAME} .*\.(jpg|jpeg|png) [NC]RewriteCond %{HTTP_REFERER} !localhost [NC]RewriteRule .* b.pngExpiresActive OnExpiresByType image/jpeg "access plus 1 month" <FilesMatch "\.(gif)$"> header set Cache-control "no-store,must-revalidate"</FilesMatch>


如何防盗链呢?

以上配置中

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} .*\.(jpg|jpeg|png) [NC]
RewriteCond %{HTTP_REFERER} !localhost [NC]
RewriteRule .* b.png

就是实现这个功能,但需要打开 apache 的  

LoadModule rewrite_module modules/mod_rewrite.so

功能


ExpiresActive On
ExpiresByType image/jpeg "access plus 1 month" 

实现图片缓存多长时间打开apache 的模块

LoadModule expires_module modules/mod_expires.so


<FilesMatch "\.(gif)$">
 header set Cache-control "no-store,must-revalidate"
</FilesMatch>

图片不实现缓存打开apache 的的模块

LoadModule headers_module modules/mod_headers.so

即可。


以上配置放在.htaccess文件中。  




0 0
原创粉丝点击