How to block file download outside from Website using .htaccess

December 8, 2022 · 1 min read

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!

How to connect MongoDB with PHP CodeIgniter.
Design a christmas tree using Python Turtle Package
Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin
Pin on Pinterest
Pinterest