大网数据广告活动
网站运营与故障问答

How to prevent hotlinking for specific domains using .htaccess?

· 52CE 我爱测

I'm being heavily spammed by image scraper sites. There are more than 150+ domains targeting my images & sending spammed links to my site. I just want to prevent hotlinking from them. I just want to block only those specific site…

问题原文

原帖链接 · Ankit Jha · CC BY-SA 4.0

I'm being heavily spammed by image scraper sites. There are more than 150+ domains targeting my images & sending spammed links to my site. I just want to prevent hotlinking from them. I just want to block only those specific sites.

Is there any htaccess rule for preventing hotlinking in specific sites only and allow others which is not included in list?

社区高分解答

原帖链接 · closetnoc · CC BY-SA 4.0

Using https://www.htaccesstools.com/hotlink-protection/

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

You may or may not need RewriteEngine on. The next line allows a blank referrer. You may need to examine your log files and may optionally remove this line.

The last two lines are the meat of the code. Change example.com to your domain name. As well, if you want to add or remove more image types, you can simply add them or remove them. Please not the | character is an or character. You need these in your list just as you see them. In this case, jpg or jpeg or png or gif.

You can certainly use the link above to do this for you.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。