Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to prevent user to access images in multiple directories via the url

I am using .htaccess to prevent user to access images through url.
Thanks to this question, I could prevent users to access .js files.

RewriteEngine ON
RewriteRule ^frontend/assets/(?:js) - [R=401,NC,L]

However, when I applied the same rules in order to denied access to dir1 and dir2, the access is only denied to images in directory dir1.

RewriteRule ^frontend/assets/images/(?:dir1|dir2) - [R=401,NC,L]

Is there a way to handle this and prevent users to access files in directory dir2 as well ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Please try following htaccess rules file. Apart from fixing regex we need to be careful on where we need to place the rule. So place this rule before your previously used rule(s).

Please make sure to clear your browser cache before testing your URLs.

##Enabling RewriteEngine here...
RewriteEngine On
##Rewrite rule for images with checking users OR uploads here...
RewriteRule ^free/frontend/assets/images/(?:users|uploads) - [R=401,NC,L]
##Rewrite rule for images OR css OS js folders here....
RewriteRule ^frontend/assets/(?:images|css|js) - [R=401,NC,L]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading