简体   繁体   English

我如何限制直接访问(从浏览器)到文件夹,但允许访问其中的图像文件..?

[英]How do i restrict direct access (from browser) to a folder but allow access to image files inside it..?

I'm having problem with htaccess. 我遇到了htaccess的问题。 what I want to do is when a user accessed my folder named images from a browser I want to restrict it, but when accessing image files inside it, I want to display the image in the browser. 我想要做的是当用户从我希望限制它的浏览器访问我的名为images文件夹时,但是当访问其中的图像文件时,我想在浏览器中显示该图像。 Tried the following code but no success. 尝试了以下代码但没有成功。

<FilesMatch "\.(gif|jpe?g|png|pdf)$">
Allow from all
</FilesMatch>

<Directory>
Order deny,allow
Deny from all
</Directory>

So, can you please suggest something? 所以,你能建议一下吗?

You can simply add an empty index.html. 您只需添加一个空的index.html即可。 This will stop the direct access to that folder. 这将停止直接访问该文件夹。

Another solution is that: 另一种解决方案是:

Options -Indexes

Enter the above code into htaccess. 在htaccess中输入上面的代码。 That will produce a 403 HTTP Status code on folder access, but will allow you do share the content ! 这将在文件夹访问时生成403 HTTP状态代码,但允许您共享内容!

选项中关闭索引。

Options -Indexes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM