Prevent hotlinking on your media files

Whenever you want to ban/prevent hotlinking your media files and protect your server’s resources and bandwidth you may use the following snippet in the .htaccess file of your main directory of your site.

Just replace YOURSITE.YOURDOMAIN with your site and at the fourth row of the actual code (don’t mind the # comment line) you can put whatever file extensions in the brackets () separated by | sign – (X|Y|Z).

How it works?

Well, it just tells the server to ban all third parties from accessing your data so only your site can display that info and that’s it.

PS: If you are a WordPress user and you don’t want to mess with any code this plugin is for you : )

Enjoy

Join the Conversation

1 Comment

  1. You will not protect your site from iframe embeds with this protection, so in order to setup a better protection, you should add this to your .htaccess:

    Header set X-Frame-Options DENY

    It is of great importance to enable mod_headers for apache, otherwise this line will lead to error 500 on your site.

Leave a comment

Your email address will not be published. Required fields are marked *