htaccess阻止域热链接图像

htaccess阻止域热链接图像

本文介绍了htaccess阻止域热链接图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阻止了文件中的某些站点,但是它们不断在我的服务器上发出请求,并询问使我的服务器速度变慢的图像,我该如何为它们添加规则,以便它们会看到大的红色标志停止热链接

I blocked some sites in the file but they keep comming on my server and asking for images that slow down my server how i can add a rule for them so they will see big red sign STOP HOTLINKING

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} ^http://(www\.)?somesite\.pl [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?somesite\.pl [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?somesite\.pl [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?sklep.somesite\.eu [NC]
RewriteRule \.(gif|jpe?g|js|css)$ - [F,NC,L]


推荐答案

伴侣尝试以下操作,

以下代码将仅允许提及的域 alloweddomain.com,并阻止其他人进行热链接

Following code will only allow the mentioned domain "alloweddomain.com" and block others from hot linking

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

以上代码将允许空白引荐来源网址

什么是空白引荐来源网址?

某些访问者使用个人防火墙或防病毒程序,该程序会删除Web浏览器发送的页面引荐来源网址信息。热链接保护基于此信息。因此,如果您选择不允许空白引荐来源,则会阻止这些用户。您还可以通过在浏览器中输入URL来阻止人们直接访问图像。

Some visitors uses a personal firewall or antivirus program, that deletes the page referrer information sent by the web browser. Hotlink protection is based on this information. So if you choose not to allow blank referrers, you will block these users. You will also prevent people from directly accessing an image by typing in the URL in their browser.

假设您不想允许空白引荐来源网址 然后使用以下代码伴侣

Suppose if you don't want to allow "Blank Referrers" then use the following code mate

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

此外,如果您想显示类似 STOP HOTLINKING 的图像,请使用以下方法

Also if suppose you want to display a image like "STOP HOTLINKING" then use the below method

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

以上代码将允许空白引荐来源网址 。不允许,再次按照上一步中的说明进行操作。

Above code will allow "Blank referrers" . To not allow, follow as mentioned in previous step again.

请注意:

如果显示 STOP HOTLINK图像,请确保该图像不受热链接保护,否则您的服务器可能会陷入无限循环。



alloweddomain.com - The domain that you want to allow for hotlink
mydomain.com/img/stop_hotlink.jpg - URL for the "STOP HOTLINK" image

更新: [阻止特定域名]

仅停止从特定外部域进行热链接,例如blockurl1.com,blockurl2.com和blockurl3.com,但允许任何其他网站进行热链接图片:

To stop hotlinking from specific outside domains only, such as blockurl1.com, blockurl2.com and blockurl3.com, but allow any other web site to hotlink images:

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blockurl1\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blockurl2\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blockurl3\.com/ [NC]
RewriteCond %{REQUEST_URI} !blocked\.gif$ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://example.com/blocked.gif [L]

您可以根据需要添加任意多个域。每行RewriteCond行应以[NC,OR]代码结尾。 NC表示忽略大小写。 OR表示与该域或下一行匹配的或下一步。列出的最后一个域省略了OR代码,因为您想在最后一个RewriteCond行之后停止匹配域。

You can add as many different domains as needed. Each RewriteCond line should end with the [NC,OR] code. NC means to ignore upper and lower case. OR means "Or Next", as in, match this domain or the next line that follows. The last domain listed omits the OR code since you want to stop matching domains after the last RewriteCond line.

最后一行包含URL ,其中包含在情况发生时将显示的图像。

The last line contains the URL "http://example.com/blocked.gif" which contains the image that will be displayed when the condition occurs.

您可以显示403 Forbidden错误代码而不是图像。用以下行替换前面示例的最后一行:

You can display a 403 Forbidden error code instead of an image. Replace the last line of the previous examples with this line:

RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]

希望这可以帮助您交配!

Hope this helped you mate!

这篇关于htaccess阻止域热链接图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 22:56