Hotlinking, htaccess and excluding subdomains

Soldato
Joined
16 Nov 2003
Posts
9,682
Location
On the pale blue dot
Hi guys,

My bandwidth is currently being sucked up by a bunch of warez and torrent sites that are leeching an image and so I've been experimenting with rules in htaccess to redirect them to a lovely picture of a a nearly-naked Todd from Scrubs. Go on, Google Image search that, you know you want to.

What I want to do it limit the impact this is going to have on legitimate requests. Therefore I have two questions:

  • What is the 'scope' of htaccess? I want to exclude subdomains from this list of rules so that my sub folders, that contain my signature picture for example, are not replaced with a naked man :eek:.
  • How can I allow 'direct' access, to images, so that if you type the address directly, you still get the correct image.
 
Direct access to your images from the address bar can be enabled by allowing blank referrers in your .htaccess rules.

Also, some firewalls and security packages will remove the referrer from requests - thus blocking legitimate visitors if you don't allow blank referrers.

There are plenty of articles about it on Google.
 
  • What is the 'scope' of htaccess? I want to exclude subdomains from this list of rules so that my sub folders, that contain my signature picture for example, are not replaced with a naked man :eek:.
.htaccess files work on the current directory they are in, all files in the directory and any other sub-directories inside (and sub-directories and files of those etc.). Note that this is based on the filesystem, so if the directories/files for your subdomains are under the same directory as your htaccess, the subdomains will inherit the rules.

You can make sure your rewrite rules either:
  • exclude specific images/folders from being rewritten
  • exclude specific referrer domains i.e. your own, your subdomains, this forum

or you can completely disable rewriting in sub-folders by adding another .htaccess file in it and turning off the rewriting engine:

Code:
RewriteEngine Off

But if you're concerned about bandwidth, why redirect to another image that's goign to suck up the same/more bandwidth? Why not just redirect to a 1x1 png or return a HTTP 404?
 
Back
Top Bottom