方法一: 使用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
SetEnvIfNoCase Referer "^ http://.*\.xxxx2\.com " local_ref
<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)"> //文件匹配
Order Allow,Deny
Allow from env=local_ref
Order Allow,Deny
Allow from env=local_ref
</filesmatch>