mod_hotlinkmod_hotlink overviewmod_hotlink module is aimed at protecting your web server from people stealing your traffic by directly linking to the content on your server. This is especially important for those having image, video, documents archives and other downloadable content. After enabling mod_hotlink your site will work as if nothing happened, all search engines and backward links will still be valid, all user’s favorites will remain working. But if someone tries to embed your stuff directly on their site, they will only see an error message or your site’s logo. You can save tons of traffic and thus money. You can even turn these hotlinks into real visitors by redirecting hotlink request to your site’s homepage. You just put directories with embedded content under protection with few directives and that's all. mod_hotlink is based on HotlinkBlocker product, but now it's just a piece of our Ape product. Protection methodsmod_hotlink offers three protection methods each having it's advantages and peculiarities: LINK: This is the most comprehensive and powerful protection method. In this mode mod_hotlink edits each link to protected content on your site by adding special cryptographic signature. You specify expiration time for the signature on the expiry of which link becomes invalid (e.g. 30 minutes after it was requested). LINK method is not sensitive to HTTP Referer modifications, disabled cookies or JavaScripts in user’s browsers. mod_hotlink in LINK mode is capable of protecting any file types including streaming media and embedded content. Starting from 3.0 version of Ape mod_hotlink is capable to add digital signature to the links on the fly, with no need to modify HTML content. REFERER: Simply checks HTTP REDIRECT: Checks mod_hotlink directivesHotlinkProtect
HotlinkProtect directive enables hotlink protection for /location_to_be_protected context using ProtectionType method. You will need at least one HotlinkProtect directive to enable protection with minimum configuration. location_to_be_protected specifies a path with protected content. Path is relative from current context. ProtectionType parameter may take one of the following values:
RedirectTo=URL is an optional parameter that allows to specify a custom page or image URL to redirect unauthorized visitors. If this parameter is not used, the unwanted person will get 403 Forbidden error. ParamName=HLB is an optional parameter that allows to specify a custom name of parameter in querystring that will be added to links when LINK protection method is used. By default parameter parameter is called HLB. Example:
HotlinkAllow
HotlinkAllow directive defines a white list record to explicitly allow requests from specific referrers, User-Agents and IPs and to bypass protection. Note! You may have several HotlinkAllow directives in one context. They are processed top-down until the first match. So it's advisable to use more general patterns after more specific ones. Example:
HotlinkDeny
HotlinkDeny directive defines a black list record to explicitly prohibit requests from specific referrers, User-Agents and IPs. Note! You may have several HotlinkDeny directives in one context. They are processed top-down until the first match. So it's advisable to use more general patterns after more specific ones. HotlinkExpires
HotlinkLinkExpires directive sets the time during which the signature is valid and thus may be used. HotlinkInvolveIP
HotlinkInvolveIP directive defines whether the client IP address is used for signature generation. This makes digital signature to be IP-related, thus clients with different IP addresses will be unable to download content using same signatures. HotlinkSignature
HotlinkSignature directive specifies the password that will be used for signature encryption. If not set explicitly, the random password will be generated automatically upon each application start for better security. This parameter is only needed when you need to share links between different servers, like in cluster. You just set identical signatures for all servers and synchronize time which makes links generated on one server to be valid on another. Advanced usage:Using environment variables to enable hotlink protectionAll mod_hotlink settings may be defined using HotlinkProtect environment variable like in mod_rewrite or any other module that accepts environment variables:
Manual signature useFor any protection type and for each request mod_hotlink generates a unique signature that is then saved in HOTLINKBLOCKER_SIGNATURE server variable. It may be extracted manually in the following manner:
This allows to use it in locations where mod_hotlink can't fix links by itself, e.g. in Flash scenarios, JavaScripts etc. Examples1. Link protection methodLink protection is completely independent on For this example we need the following files in the root of the site:
default.html page should have the following tag inside:
.htaccess must be configured as follows:
When the user requests default.html mod_hotlink replaces links in the tag with specifically generated sequence:
How it works:
2. Referer protection methodThe task is to protect all images from hotlinking; allow referers from your own site and empty referers.
How it works: When a browser makes a request, it passes Say you have a page default.html on your site www.yourdomain.com and there's also a link
Note! If you directly put the address of the resource into the browser address bar (e.g. http://www.yourdomain.com/img/picture.gif),
3. Redirect protection methodRedirect method is usually used to protect .pdf and .swf files as Internet Explorer sets incorrect
How it works:
All this stuff is necessary to bypass noncompliance of some browsers with the standards (especially this refers to Internet Explorer) as they sometimes don't set Referer header for successive requests to the same resource. |