htaccess deny direct access to folder in website
×


htaccess deny direct access to folder in website

0 12321

Anybody can open your folder directly by writing folder names 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:

http://websitename.com/images_folder
or
http://websitename.com/css

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


How to prevent this?

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

Steps to deny direct access through .htaccess

1 Create a .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.

Result:

  • However, if you want to prevent direct access only for a certain folder follow these steps.

Step 1 Create a .htaccess file into that particular folder and put the given code in that file.

deny from all

Now, if you try to access any file or folder inside this particular folder, it will throw an error.

Example: I have a folder check in my root directory.

When I open it in the browser, it looks like this.

Means anyone can easily access the above files and folders. To secure the code inside the check folder, create a .htaccess file inside it and put the given code there.

deny from all

Now open this folder in the browser again.

Now it does not permit to open any directory or file inside it.


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.

Use the method elaborated above and you will see the results.


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!


.htaccess topics:



Share:


Leave a Reply


Comments
    Waiting for your comments