Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

Block Blacklisted Bandwidth Thieves from Hotlinking Your Image Files

Code for an .htaccess file located in a directory containing images (or any other type of file for that matter) to which you want to block hotlinking from blacklisted websites.
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?evilwebsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://forum\.evilwebsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?bandwidththieves\.net [NC]
RewriteRule \.(jpeg|jpg|gif|bmp|png|JPEG|JPG|GIF|BMP|PNG)$ http://example.com/pwnt.gif [L]

example.com/pwnt.gif
is the location of the file you want to serve in place of the hotlinked image. Mine just says 'PWNT'.

Alternate last line to simply block the images from being hotlinked instead of serving a replacement image:
RewriteRule \.(jpeg|jpg|gif|bmp|png|JPEG|JPG|GIF|BMP|PNG)$ - [F]

mod_rewrite rules to serve application/xhtml+xml

The following mod_rewrite rules will serve HTML files as application/xhtml+xml to supporting browsers.

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0
RewriteCond %{REQUEST_URI} \.html$
RewriteCond %{THE_REQUEST} HTTP/1\.1
RewriteRule .* - [T=application/xhtml+xml]


Source: Mark Pilgrim, The Road to XHTML 2.0: MIME Types.
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed