Hi all!
Below is the code, I am sharing for restricting and blocking the file download from outside of your website.
You can put the below code in .htaccess file to restrict the access.
RewriteCond %{HTTP_HOST}@@%{HTTP_REFERER} !^([^@]*)@@https?://\1/.*
RewriteRule \.(gif|jpg|jpeg|png|tif|pdf|wav|wmv|wma|avi|mov|mp4|m4v|mp3|zip?)$ - [F]
This code will block & restrict the access of your file’s access outside from your website.
If you want to block the direct access of any directory, you can put the below code in your .htaccess file.
Options -Indexes
Thanks – Happy Coding!