deny access to directory listing using htaccess

被刻印的时光 ゝ 提交于 2019-12-24 17:48:00

问题


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.



来源:https://stackoverflow.com/questions/37874618/deny-access-to-directory-listing-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!