.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]
Posted in
latest posts
About
Hi, I'm Ivan Soto Fernandez (yes, two last names). I'm a chilean web developer living in Edmonton, Canada. I'm also an anime fan, Gundams lover and gamer. Welcome to my blog.
You can read more about me or follow me on Twitter or any of the following social websites.