.htaccess hotlink protection

Jan 16, 2009
Protecting your site from hotlinks can be really useful to prevent other sites stealing bandwidth, but it's also comes handy when you want to protect files from private areas. The first 2 lines are responsible from redirecting all the traffic from www.yoursite.com to yoursite.com and the third and fourth line is for preventing hotlinks, in this case PDFs and SVGs. You can add more file types.
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

RewriteCond %{HTTP_REFERER} !^http://yoursite.com [NC]
RewriteRule .*\.(SVG|pdf)$ http://yoursite.com/nohotlinking [NC,R,L]

Post new comment

You can use your Gravatar account.

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated.