Prevent hotlinking to your site's images, thus potentially saving a ton of bandwidth.
Prevent Other Sites from Embedding Your Images
Lately, I've had clients who have experienced image theft via hotlinking. Unfortunately, many ApacheConf code snippets don't work well. Below, you'll find the code you should use. However, keep in mind the following:
Place Code in an IfModule
If you don't do this, and the module is not active, you're in for a world of hurt.
The following snippet allows for both www and non-www domains in a single line.
The snippet also used REQUEST_FILENAME to identify the requested filenames rather than the referring domain. I believe this is more optimal.
Checks if requested file exists
Since we're serving an anti-hotlinking image, checking whether or not the file exists saves bandwidth if a requested file does not, in fact, exist.
Utilizing of the
[NC]flag ensures casing does not matter, meaning both uppercase and lowercase letters are treated as the same.
Allows Your Subdomains
([^.]+\.)?regex, in line #6, your subdomains will not be blocked.
Search Engine Access
Due to the fact that we want search engines to find our images, lines 7-9 allows for their access.
Thank you for reading.