How to block accessing wp-content/uploads

Viewed 584

I try to create a Wordpress site for a Photographer, so I block the right click but it always possible too access too the url where images is uploading. I tried to block with the file .htaccess and the plugind "Prevent Direct Access" but it's not working.

There is any thing who can block the access ?

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{HTTP_REFERER} !^$
 RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.be [NC]
 RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
 RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?facebook.com [NC]
 RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?twitter.com [NC]
 RewriteRule \.(jpg|jpeg|png|gif)$ - [F] 
</IfModule>
1 Answers

To prevent anyone from accessing any PHP files in the wp-content/uploads folder, you can create a .htaccess file in the wp-content/uploads folder and add the following code to it:

# Kill PHP Execution
<Files ~ ".ph(?:p[345]?|t|tml)$">
deny from all
</Files>

You can add the below code to your .htaccess file.

# Deny access to .htaccess

<Files .htaccess>

Order allow,deny

Deny from all

</Files>

Open up your .htaccess found on the root folder of your website then place the block of code bellow:

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L]

To hide sensitive files in the wp-includes folder, add the following code to the .htaccess file in the root of your site:

 # Block wp-includes folder and files
 <IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^wp-admin/includes/ - [F,L]
 RewriteRule !^wp-includes/ - [S=3]
 RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
 RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
 RewriteRule ^wp-includes/theme-compat/ - [F,L]
 </IfModule>
Related