Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
Created May 8, 2023 15:14
Show Gist options
  • Save danielcharrua/81f99499bcb816b40c6eba840f2c5142 to your computer and use it in GitHub Desktop.
Save danielcharrua/81f99499bcb816b40c6eba840f2c5142 to your computer and use it in GitHub Desktop.
Disable access to files inside WordPress upload sub-folder with cookie
# This file must be placed inside the directory eg. wp-content/uploads/documents
# Will prevent direct access for anyone but a logged-in user with a valid wordpress_logged_in cookie
RewriteEngine on
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment