how to protect wp-content from download


I have some protections with htaccess but I have a problem. I m still able to download a file if I know the name.

How I could disable download if not a link from my website (disable link from address bar or link from other website)

I know plugin can do that but I would prefer using htaccess system

Otherwise, is there a way to give a random and complicated name to all files uploaded?

Thank you

  • Ash
    • WordPress Hacker

    Hello @Ludovic

    I hope you are well today.

    Okay I have found two other possible ways:

    1. Create a htaccess file in uploads folder and add following two lines:

    Order Deny,Allow
    Deny from all


    2. Add following in root htaccess:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} \.(doc|zip|pdf)$ [NC]
    RewriteRule ^(.*)$ /download-file.php?filename=$1 [L]

    Then create download-file.php file and add your message here. You need to doc|zip|pdf to match your file extensions.

    Please let us know if that works.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.