3 ways to Deny Download Access on your file Apache Htaccess WordPress

1. Using .htaccess:

Upload a .htaccess file into your sites root folder. Have a look if one exists already, then append this code to the end of the file. If the file is all ready there, then you don't need to add this part "RewriteEngine On". However, if you don’t have one, just create a new blank file and add this code to it and then simply save it as .htaccess

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourwebsite\.com/ [NC]
RewriteCond %{REQUEST_URI} !hotlink\.(mp3|mp4|mov) [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule .*\.(mp3|mp4|mov)$ http://yourwebsite.com/ [NC]

Please nOte: If these conditions are not met, then give out the file – everyone’s happy.

2. Create a new file in your mp3 directory called index.php, and add this code to it

// Display no content

What this is doing is when a user goes to browse your directory, the web server will serve them the index.php file. Since there is no code in it, the user will be served a blank webpage as a result.

3. Do this through .htaccess In your website's root directory should be a .htaccess file. Open this up and add
this nasty little redirect:

Redirect 403 /mp3/ http://mysite.com

The Redirect will automatically redirect anyone who tries to access the /mp3/ folder via the browser url and send them to your main website of mysite.com. The 403 tells the browser that the request is Forbidden 🙂