Skip to content

Instantly share code, notes, and snippets.

@alchemycs
Created February 15, 2012 00:03
Show Gist options
  • Save alchemycs/1831823 to your computer and use it in GitHub Desktop.
Save alchemycs/1831823 to your computer and use it in GitHub Desktop.
Apache config for restricting images based on referrer
# This stops others from using simple links to your media on their site. See comments at end of GIST for limitations
# Prevents sites you don't own placing simple embeds on those sites. eg <img src="http://example.com/images/sample-image.png"/>
RewriteCond %{REQUEST_URI} ^/images/.*
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com(/)?.*$ [NC]
RewriteRule .* - [F]
# Your bandwidth is precious and others shouldn't poach your bandwidth.
# - If someone wants to use media you have on the internet they can get it one way or another
# - Does not protect against spoofed headers
# - Doesn't stop people from right-click > download image/file (etc)
@alchemycs
Copy link
Author

Usage

Ok, someone mentioned to me that this will deny SSL sites. I thought that was kind of obvious, so here are some more usage notes:

  1. Make sure /images/ on line 3 is an actual path to a folder off your document root you want this to apply to
  2. Make sure http on line 4 is https if you have an SSL site
  3. Change example.com to reflect the domain your configuration is hosting for

I think that's it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment