How to Restrict Access to All Files in /wp-content/uploads/wpforms/ Folder Without Plugins (Using .htaccess or Code)?

I'm trying to restrict public access to all files in the /wp-content/uploads/wpforms/ folder on my WordPress site, but I'm having trouble finding a solution that works. I want to make sure that only logged-in users can view or download files in this folder. I've tried various .htaccess solutions, including blocking or redirecting access, but none seem to work for files like PDFs, which can still be accessed directly by their URL. Here’s what I need: Restrict all files inside /wp-content/uploads/wpforms/ folder from being accessed publicly. Ideally, I want a solution using .htaccess or PHP without using any third-party plugins. I’m okay with either blocking the files entirely or redirecting users to a specific page if they try to access these files. Is there a specific .htaccess rule or a custom PHP function that would accomplish this? I appreciate any advice or example code you can provide! Thanks in advance!

Comment (0)

You’ll be in good company