deny access to directory listing using htaccess

2019-07-25 16:19发布

问题:

I want to deny access to particular directory to show list of files in it in the browser. For example, If I go to the url, localhost/myproject/assets, it will show all the list of files in it, I want to deny that. And also if logged in user access specific file in it, for ex : localhost/myproject/assets/uploads/img/1.jpg then it should be accessible. Also how to deny access to a localhost/myproject/assets/uploads/img/1.jpg if that 1.jpg is uploaded by some other user.

I'm new to laravel ,Any help is much appreciated. thanks

回答1:

If you are using Apache, you can place a .htaccess file in the folder you want to block. Then you can use deny from all to block all requests to that folder.

This works because a .htaccess file can be in every directory in your web root, and only cares about the directory it is in and its subdirectories.

See this answer.



回答2:

You could add the following to the .htaccess file in the folder. This might help.

Options -Indexes

You cannot deny the access to the jpg uploaded by another user.