One way to kill your website's bandwidth and overall download speed is to not block image "hotlinking." What's hotlinking? Hotlinking is linking to a file on an external server that the Web Developer does not own (most of the time the Web Developer doesn't even have permission to use the file). Hot linking occurs mostly with images.
杀死网站带宽和整体下载速度的一种方法是不阻止图像“热链接”。 什么是热链接? 热链接是链接到Web开发人员不拥有的外部服务器上的文件(大多数情况下,Web开发人员甚至没有使用该文件的权限) 。 热链接主要发生在图像上。
Why would another website hotlink to a file on your server? There are a variety of reasons, both innocent and evil:
为什么另一个网站热链接到您服务器上的文件? 有多种原因,包括无辜和邪恶:
- To use up the other website's bandwidth / save your bandwidth (evil) 耗尽另一个网站的带宽/保存您的带宽(邪恶)
- To link to an oft-changing file so that the file is always up to date on your website (mostly innocent) 链接到经常更改的文件,以便该文件在您的网站上始终是最新的(大多数情况是无害的)
- Laziness (both) 懒惰(两者)
How can this be prevented? Relatively easily using some quick .htaccess directives.
如何预防? 使用一些快速的.htaccess指令相对容易。
代码 (The Code)
The following prevents any domain beside yours from hotlinking:
以下内容可防止您旁边的任何域进行热链接:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yourwebdomain.com(/)?.*$ [NC]
The following allows only a friend to hotlink -- everyone else is barred:
以下内容仅允许朋友进行热链接-禁止其他所有人:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yourwebdomain.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?friend1domain.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www.)?friend2domain.com(/)?.*$ [NC]
The following allows for protection of only specified file extensions:
以下仅允许保护指定的文件扩展名:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yourwebdomain.com(/)?.*$ [NC]
RewriteRule .*.(gif|jpe?g)$ [F,NC]
The following returns a "stop stealing my images" image:
以下返回“停止窃取我的图像”图像:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yourwebdomain.com(/)?.*$ [NC]
RewriteRule .(gif|jpe?g|png|bmp)$ /graphics/stop-stealing.jpg [L,NC]
You can use the above coding practices to prevents thievery of any type of file you'd like, including CSS, JavaScript, and text files.
您可以使用上述编码方法来防止任何类型的文件,包括CSS,JavaScript和文本文件。