Reputation: 625237
I came across a site that demonstrated a Javascript library and it asked that you please not link to the Javascript file directly from your site. That's a reasonable request. In fact, it wouldn't have occurred to me to do that instead of hosting it myself but I guess will try and save on bandwidth any way they can.
This got me thinking: does Apache (in a shared hosting environment) come with any simple means of either preventing this or at least making it a little more difficult by looking at the HTTP_REFERRER or the likes? Or perhaps even just ensuring you have a PHP session?
Upvotes: 0
Views: 852
Reputation: 915
Using an htaccess file you can do this.
Simply create a .htaccess file in the directory of the files you wish to protect with the following inside it:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com(/)?.*$ [NC]
For more information and some other things you can do to prevent hot linking at the web server level see Dev Papers article on Preventing Hotlinking
Upvotes: 5