Search code examples
regexapache.htaccesshotlinking

disable direct linking to my files from the user's browser


I'm using the following .htaccess configurations to disable hotlinking :

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)mywesbite.com/.*$ [NC]
RewriteRule \.(flv|mp4|pdf|xls|doc|mov|wmv|avi)$ http://www.mywebsite.com/images/logo.jpg [R,L]


And I've tested it and everything is working fine, and now I want to disable downloading the files when the user tries to add the direct link of one of the files to his browser's address bar. Only the users that are referred to the file from my website can download it. Is there any way I can get that done by adding some more .htaccess configurations?


Solution

  • RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?mywebsite.com(/)?.*$     [NC]
    RewriteRule .*\.(flv|mp4|pdf|xls|doc|mov|wmv|avi)$ http://www.mywebsite.com/images/logo.jpg [R,NC]
    

    Alternative if that doesnt work

    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?mywebsite.com(/)?.*$     [NC]
    RewriteRule .*\.(flv|mp4|pdf|xls|doc|mov|wmv|avi)$ http://www.mywebsite.com/images/logo.jpg [R,NC]