Base de connaissances

Prevent hotlinking with a .htaccess file  Imprimer cet article

OVERVIEW

Hotlinking refers to linking directly to non-html objects on other servers, such as images, movie files etc. This can greatly impact bandwidth usage and, in some cases, GPUs if you are on the Grid. You can prevent these requests on your server using a .htaccess file.

REQUIREMENTS

Before you start, be sure to have handy:

  • Your FTP login credentials and an FTP client.
  • SSH credentials
  • or File Manager access
  • Plain text editor

READ ME FIRST

The publishing of this information does not imply support of this article. This article is provided solely as a courtesy to our customers. Please take a moment to review the Statement of Support.

INSTRUCTIONS

If you already have an .htaccess file simply add one of these two snippets of code to your existing file, or create a new plain text document with this code and upload it to your domains directory or a particular sub directory to localize the effect to just one of your sites or section of one of these sites:

Stop hotlinking

To simply stop hotlinking you can add the following to your .htaccess file. Replace example.com on line 3 with your own domain name.


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)example.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|bmp|zip|rar|mp3|flv|swf|xml|php|png|css|pdf)$ - [F]

Serve alternate content

To serve alternate content when hotlinking is detected. You can set up your .htaccess file to actually display different content when hotlinking is attempted. This is more commonly done with images suggesting your displeasure of this activity, such as serving up an "Angry Man" image in place of the hotlinked one. Once again, replace example.com on lines 3 and 4 with your own domain name.

 


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)example.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.example.com/angryman.gif [R,L]

Cette réponse était-elle pertinente?

Articles connexes

Why didn't my email get delivered, where did my email go, email problems, email bounce, or email daemon?
Using cpanel, Technical Analysts will get asked these questions many times. Unfortunately there...
ICANN Domain Ownership Verification Email
Changes that have occurred within the Registrars Accreditation Agreement (RAA- Registrar...
How to test your website on Ionblade's server with your computers "hosts" file
Why Change the Hosts File? Changing your hosts file is a temporary measure to preview your...