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 css files and images via the url

I am using .htaccess to prevent user to access files through url.
The line

RewriteRule ^frontend/assets/css/(.+) index [L,R]

works fine. It prevents users to access css files.
However,

RewriteRule ^frontend/assets/images/(.+) index [L,R] //Images

as well as

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

RewriteRule ^frontend/assets/js/(.+) index [L,R] //Javascript files

do not work.
I have tried multiple solutions but still I can access js and images (png and svg) files from the url.
Is there a way to handle this ?

>Solution :

Please following rules at the top of your htaccess rules file. You need not to create 3 separate rules for 3 conditions, you can use regex here and can do a 401 redirect for all of 3 strings(js/images/css) in a single rule itself.

Make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
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