HostMonster Web Hosting Help

Hotlink Protection

Summary

You can use the .htaccess file to enable HotLink Protection on your site. This will prevent people from linking to your images.
Note: You can also enable hotlink protection through the cPanel interface, or with mod_rewrite.

Apache has a built-in method for protecting images within directories from prying eyes, using the .htaccess file.

When your browser sends a request for an image, it usually also sends the URL of the page that linked to that image. The following .htaccess file causes the server to check this URL ("Referer" in the following snippet) and, if it is one of the authorized URLs that you specify, it will set an internal flag called "locally_linked". This internal flag is technically called an "environmental variable". If the URL sent is not in this list of authorized URLs, the flag (or ev) is not set. Note that we also set the "locally_linked" variable if the browser does not send any URL at all: this occurs when the visitor accesses your site using a browser or a proxy that suppresses the referring URL.

The web server then checks if the file requested has an extension in the list given below (gif, png, jpg and jpeg). If so, and the "locally_linked" variable is set, it will send the image. Otherwise, an error will be sent. If this is too complex, then you can use the Hotlink manager or the Password Protect icon in the cpanel.

SetEnvIfNoCase Referer    "^http://www.example.com/" locally_linked=1
        SetEnvIfNoCase Referer "^http://www.example.com$" locally_linked=1
        SetEnvIfNoCase Referer "^http://example.com/" locally_linked=1
        SetEnvIfNoCase Referer "^http://example.com$" locally_linked=1
        SetEnvIfNoCase Referer "^$" locally_linked=1
        <FilesMatch ".(gif|png|jpe?g)$">
          Order Allow,Deny
          Allow from env=locally_linked
        </FilesMatch>
Knowledgebase Article 62,898 views bookmark tags: hotlink htaccess protection (updated 1102 days ago)


Was this resource helpful?

Did this resolve your issue?


Please add any other comments or suggestions about this content:





Recommended Help Content

How can I protect the images on my website? (updated 1449 days ago)
Knowledgebase Article 131,995 views tags: click code image images javascript protect save saving script tips tricks

Preventing bandwidth theft using the mod rewrite engine and .htaccess (updated 1103 days ago)
Knowledgebase Article 102,682 views tags: htaccess rewrite

How do I setup Hotlink Protection? (updated 1102 days ago)
Knowledgebase Article 92,663 views tags: link protection

Related Help Content

How do I password protect a folder on my website? (updated 298 days ago)
Knowledgebase Article 92,955 views tags: folder password protect

This tutorial will show you how you can password protect parts of your website by password protecting the folder(s) on your account. (updated 298 days ago)
Video "How-to" Tutorial 126,441 views tags: cpanel cpanelutilities login password protect

Why don't my images display on my site? (updated 2101 days ago)
Knowledgebase Article 93,895 views tags: display image images link site website

This article will show a way to protect specific pages of your website with SSL. This may have benefits for SEO and can be used on pages that contain forms, shopping carts or any other page where users might enter sensitive information. (updated 93 days ago)
Knowledgebase Article 1,620 views tags: htaccess pages specific ssl

What is the .htaccess file and where can I find more information? (updated 833 days ago)
Knowledgebase Article 1,456,599 views tags: htaccess tips tricks

What should I do if I am having problems with multiple password prompts on my password protected directory? (updated 2120 days ago)
Knowledgebase Article 80,940 views tags: folder password protect

How do I make a sub directory (or sub folder) act as the public_html for your main domain? (updated 125 days ago)
Knowledgebase Article 567,726 views tags: Drupal domain htaccess joomla wordpress

How do I Password Protect a single file on my website? (updated 1094 days ago)
Knowledgebase Article 107,817 views tags: file passwd password prompt protect secure single