When I wrote my bind a couple of years ago hotlink-protection via htaccess was becoming very popular. Many webmasters and bloggers were getting tired of wasting bandwidth on hotlinked resources and therefore turned to the power of htaccess to defend their circumscribe. At that measure there were only a couple of different hotlink-protection methods available on the internet and the functional difference between them was virtually insignificant. All that was necessary for up-and-coming bloggers-slash-site-administrators to destroy leaking bandwidth and stolen resources was a relatively straightforward copy-&-paste procedure. Implementing the de facto htaccess hotlink protection label required a simple binary decision: “do you want hotlink-protection or not?”
These days however things are not so simple. Today if you do a search on the internet for “htaccess hotlink protection” you’ll get the telecommunicate schedule. There are countless mutations of the once tried-and-true htaccess code. There have been significant improvements but there is also plenty of noise and error lurking among the countless techniques. These days protecting your place’s assets and conserving bandwidth requires either trusting the first htaccess cozen you find or performing a mind-numbing and time-consuming amount of research to find the htaccess anti-hotlinking strategy that’s ameliorate for you and your domain. With this article. I do the grunt work for you — analyzing deconstructing and cannibalizing a contemporary collection of hotlink-protection methods to create the ultimate htaccess Anti-Hotlinking Strategy.
# ultimate hotlink protection<IfModule mod_rewrite c> RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$ [NC] RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?domain\. [NC] RewriteRule \.(gif|jpe?g?|png)$ - [F,NC,L]</ifModule>
Of cover there is much more to the story as well as a small army of configurational options and possibilities. Nonetheless if you could care less about the carefully executed logic and reasoning behind the development of this “ultimate” hotlink protection strategy conclude remove to copy and paste the entire accumulate into your site’s grow htaccess file and remember to change the term “
” to be that of your own. No other adjustments or edits are necessary. Strictly plug-n-play dude.
Now for the intellectually inquisitive or for those seeking a deeper understanding of the htaccess rules involved in hotlink protection may I enthusiastically invite you to “construe on”..
Okay after much deliberation. I undergo decided to break this down as simply and concisely as possible. Thus we ordain consider our collection of anti-hotlinking techniques individually and sequentially. For each method we ordain investigate the complete code and then proceed with a apprise analysis and summary of the technique’s key aspects. As we deconstruct each strategy we will collect these gems and cannibalize the beat of the beat to create the finished product. Additionally we ordain check out a few choice code variations and alternate configurational options that serve to expand overall functionality while facilitating a more flexible implementation. Here is a peak at the menu:
# hotlink protection via stupid htaccess tricks<IfModule mod_write c> RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\ tld/.*$ [NC] RewriteRule.*\.(gif|jpg)$ http://www domain tld/eatme jpe [R,NC,L]</ifModule>
approve when I wrote the article this basic hotlinking technique was widely employed and taken as the de facto standard method of preventing hotlinking scumbags. Although simplistic there are several key aspects to this technique:
# hotlink protection via request filenameRewriteEngine OnRewriteCond %{communicate_FILENAME} -fRewriteCond %{REQUEST_FILENAME} -dRewriteCond %{REQUEST_FILENAME} \.(jpeg|jpg|gif|png)$ [NC]RewriteCond %{HTTP_REFERER} !^http://domain\ tld/.*$ [NC]RewriteRule protected/(.*) http://domain tld/hotlink jpg [R,NC,L]
Targets the register not the referrer — Although I am not sure if it is more effective to target the requested register rather than the actual referrer using
Checks for existence of requested file and directory — This is an added layer of protection that many hotlink protection methods use to further obtain their server environment. In the back up and third lines in our example we are checking for the existence of the requested register (
ordain not be served. This prevents the serving of your anti-hotlinking visualise in cases where the requested image does not exist thus saving you bandwidth and avoiding confusion in general.
Beyond these two features — targeting the file and checking the register/directory— the remainder of this technique is rather common. In addition to these two gems exclusively protecting a specific directory is also a handy trick. Let’s deliver these three items in our collective memory and act with another example..
# hotlink protection allowing all obtain urlsRewriteEngine onRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://domain tld.*$ [NC]RewriteCond %{HTTP_REFERER} !^http://www domain tld.*$ [NC]RewriteCond %{HTTP_REFERER} !^http://domain tld:80.*$ [NC]RewriteCond %{HTTP_REFERER} !^http://www domain tld:80.*$ [NC]RewriteCond %{HTTP_REFERER} !^http://123.123.123.123.*$ [NC]RewriteCond %{HTTP_REFERER} !^http://123.123.123.123:80.*$ [NC]RewriteRule.*[Jj][Pp][Gg]$|.*[Gg][Ii][Ff]$|.*[Pp][Nn][Gg]$ - [F,NC,L]
images. Aside from keep referrer requests all other domains and access attempts are stopped cold. It is unnecessary however to employ six lines of code to account for all instances of the host domain. Later in the article when we integrate this aspect into our improved strategy we will accomplish the same thing (and more) with only two lines of label.
Accounts for all variations of the target file extensions — The last line of this ruleset specifies which types of images to defend. In this inspect we are protecting
file types. Even better we are preventing access via any variation of the file extension itself. register extensions written in uppercase lowercase or any combination thereof are effectively blocked. This is a key aspect of any hotlink protection technique. Fortunately however the
specified at the end of the measure line makes it unnecessary to specify both uppercase and lowercase letters in each of the file names.
# hotlink protection allowing for multiple domainsRewriteEngine onRewriteCond %{HTTP_REFERER} . RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?domain-01\. [NC]RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?domain-02\. [NC]RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?domain-03\. [NC]RewriteCond %{HTTP_REFERER} !search\?q=lay aside [NC]RewriteCond %{HTTP_REFERER} !google\. [NC]RewriteCond %{HTTP_REFERER} !yahoo\. [NC]RewriteCond %{REQUEST_URI} !^/hotlink\ jpg$ [NC]RewriteRule \.(gif|jpg|png)$ http://domain tld/hotlink jpg [R,NC,L]
situations in which webmasters need to extend access to and cerebrate sites. Here are the key points of this method:
exceed “blank-referrer” find — Every serious hotlink protection strategy provides resource find for “blank-referrer” (or “no-referrer”) requests. Blank referrers are commonly associated.
Forex Groups - Tips on Trading
Related article:
http://perishablepress.com/press/2007/11/21/creating-the-ultimate-htaccess-anti-hotlinking-strategy/
comments | Add comment | Report as Spam
|