1

I am trying to disable direct URL access (for images, PDF) to my WordPress websites for non-logged-in users, I have created one '.htaccess file' under - wp-content/uploads/.htaccess

RewriteCond %{REQUEST_FILENAME} ^.*(mp3|m4a|jpeg|jpg|gif|png|bmp|pdf|doc|docx|ppt|pptx|)$
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule . - [R=403,L]

this worked in Apache (localhost), but when I am trying to upload the same in Nginx (siteground), it's not working.

5
  • .htaccess is an Apache configuration file. Nginx doesn't use them. You'll need to find a different solution. Is this a VPS? Can you edit the Nginx configuration files? Sep 13, 2022 at 10:11
  • @StephenOstermiller no, let me find another method
    – Ricky
    Sep 13, 2022 at 10:46
  • As long as you're using WordPress, you might as well use a plugin for this. There are several that are well maintained that will accomplish this for you. Otherwise, you're going to have to write a script to check if a user is logged in (is_user_logged_in() will be helpful) and proxy requests to the filetypes you're interested in restricting. Sep 13, 2022 at 14:22
  • @MikeCiffone yes, few free plugins are there which didn't work for nginx, paid plugins are there with budget of more then 500 $, trying to fix this from my side, thanks :)
    – Ricky
    Sep 14, 2022 at 6:13
  • @MikeCiffone yes, 'is_user_logged_in()' is protecting the page and that's what I am doing, but direct url of media file is accessible
    – Ricky
    Sep 14, 2022 at 6:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.