两种方法实现Apache防盗链

来源:互联网 发布:雷蛇云驱动mac版怎么用 编辑:程序博客网 时间:2024/04/30 21:59

方法一: 使用rewrite方式

在Apache的主配置段添加以下内容

<IfModule rewrite_module>

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http://www.abc.org/.*$ [NC]

RewriteCond %{HTTP_REFERER} !^http://abc.org/.*$ [NC]

RewriteRule \.(jpg|gif|zip)$ http://www.404.html [R=301,L]

方法二:使用FilesMatch


在Apache的主配置段添加以下内容

SetEnvIfNoCase Referer "^http://www.xxxx1\.com" local_ref
SetEnvIfNoCase Referer "^http://.*\.xxxx2\.com" local_ref
<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)">                             //文件匹配
Order Allow,Deny                        
Allow from env=local_ref 
</filesmatch> 

0 0
原创粉丝点击