2
votes

For my Wordpress site, I currently force all users to log in to view any page or post. For example, anyone going to www.mywebsite.com or www.mywebsite.com/a-wordpress-page/ will have to sign in in order to view it.

However, anyone can currently forcefully browse to any file uploaded in the Media Library without needing to log in. For example, anyone can go to www.mywebsite.com/wp-content/uploads/2013/10/myfile.jpg without needing to log in. I want to redirect them to the login screen if possible.

Is it possible to protect this URL? What is the best solution for this? Thanks in advance.

Some things I've tried but they didn't really work...

1

1 Answers

0
votes

Include a .htaccess file in /wp-content/uploads that contains these conditions:

 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 checks if the user is logged in or not. If not, it produces a 403 error. Can also be rewritten to direct the user to the login page.