Code behind the protection (.htaccess) Hotlink protection


I need to protect the /images folder to not show images when people type in the correct URL like


Using hotlink protection.... Oh you want more?
How to protect your images from prying eyes

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 with in 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 it an error will be sent. If this is to complex then you can use the hotlink manager, or the password protect icon in the cpanel.

SetEnvIfNoCase Referer "^" locally_linked=1
SetEnvIfNoCase Referer "^$" locally_linked=1
SetEnvIfNoCase Referer "^" locally_linked=1
SetEnvIfNoCase Referer "^$" locally_linked=1
SetEnvIfNoCase Referer "^$" locally_linked=1

Order Allow,Deny
Allow from env=locally_linked

  • 0 brukere syntes dette svaret var til hjelp
Var dette svaret til hjelp?

Se også:

How do I password protect a folder on my website?

Do not follow the steps below if you are using frontpage extensions on your site. Doing so will...

Password Protect a File

The easiest method of password protecting a single file on your hosting account is to first...

Why don't my images display on my site?

If the images are uploaded in the correct location and your code references each image correctly,...

Hot Link Protection

Setup of Hot Link Protection 1. Log into cPanel 2. Go to Hot Link Protection Fields URLs to...

How do I create a PGP certificate?

First you will need to go to the File Manager and create a folder with the name of .gnupg in the...