Hotlink Protection

Problem:

I need to protect the /images folder to not show images when people type in the correct URL like www.mydomain.com/images/ to protect from prying eyes.

Solution:

Hotlink protection, Password protecting, or chmod could help you, this can be done several ways, the way you should protect a directory of files or images. 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.

     ---------------code-----------------------------------------------------------
     SetEnvIfNoCase Referer "^http://www.your-domain-name-here.com/" locally_linked=1
     SetEnvIfNoCase Referer "^http://www.your-domain-name-here.com$" locally_linked=1
     SetEnvIfNoCase Referer "^http://your-domain-name-here.com/" locally_linked=1
     SetEnvIfNoCase Referer "^http://your-domain-name-here.com$" locally_linked=1
     SetEnvIfNoCase Referer "^$" locally_linked=1
     <FilesMatch ".(gif|png|jpe?g)$">
       Order Allow,Deny
       Allow from env=locally_linked
     </FilesMatch>
  
  • 30 Users Found This Useful
Was this answer helpful?

Related Articles

URL redirect/rewrite using the .htaccess file

Problem: How do I perform a URL redirect/rewrite using the .htaccess file? Solution: .htaccess...

How to host the Primary Domain from a subfolder (.htaccess)

How do I make a sub directory (or sub folder) act as the public_html for your main domain? The...

Redirects that do not work due to PHP variables

Problem: The redirection of www.yourdomain.com/default.html or index.html to...

Redirect

Problem: How do I create a redirect? Solution: The Redirects tool will allow you to redirect...

Restrict subdomain access to addon domains

Problem: How do I stop people from being able to use the addon domain as a subdomain of the...