htaccess deny direct access to folder in website

htaccess deny direct access to folder in website

0 10814

Anybody can open your folder directly by writing folder name such as images, JS, and CSS along with URL Link and steal all files from that folder.

i.e. If you enter the image folder name with URL Link, it will display all the files inside that image folder.

Such as:
Through the above example, anyone can display entire files on CSS or image folders.

How to prevent this?

By adding just two lines code in .htaccess file, we can prevent direct access of any folder.

Steps to deny direct access through .htaccess

1. Create .htaccess file on the website.

you just need to copy and paste the following simple code in your .htaccess file.

# directory browsing
Options All -Indexes

2. Save it. This will never permit users to open files directly.


What is .htaccess?

.htaccess acts as a configuration file that permits configuration modifications on a per-directory basis.

Now the question is how we can block direct access to folders?

The exact answer is through .htaccess.

Do you think there are other concepts that I may include in this blog? Share with me through the comment box below !

I would love to hear from you

Also, don't forget to like this post and share it with your peers!

How can I redirect URLs with .htaccess

.htaccess topics:


Leave a Reply

    Waiting for your comments