问题描述
更具体地说,我有一个htaccess文件,该文件可限制任何人查看目录内容。这样,没人能通过使用以下命令在www.example.com/images中看到我的1000张图像:
从所有$ b中拒绝$ b allow from 127.0.0.1
不过,我想在www.example.com上使用这些图片这样,
< img src = images / thisimg.jpg />
起作用。
如何保护所有目录内容,但可以访问php脚本,但是我想链接到该目录中的这些图像,并且使用
拒绝所有
不允许我这样做那。 在此先感谢您的帮助。
所有您需要的该目录下的index.php或.html文件可防止人们看到目录内容。任何对yoursite.com/images的请求都将加载index.php,您将其设置为虚拟页面。
index.html可能类似于:
< html>< title> Forbidden!< / title>< body>在这里什么也看不到...< /正文>< / html>
或重定向脚本index.php:
<?php标头('Location:/index.php');出口(); ?>
不要使用.htaccess阻止目录列表,它会阻止对所有内容的访问。
More specifically, I have an htaccess file that restricts anyone from seeing the directory contents. Such that, nobody can see my 1000s of images in www.example.com/images by using:
deny from all
allow from 127.0.0.1
However, I want to use these images on www.example.com such that,<img src="images/thisimg.jpg" />
works.
I hope I'm in the right direction, but I appreciate any insight/re-direct. This is similar to: How to protect all directory contents, but gain access to php script but I want to link to these images in that directory, and using deny from all
does not allow me to do that.
Thanks in advance for your help.
All you need to keep people from seeing the directory contents is an index.php or .html file in that folder. Any requests for yoursite.com/images will load index.php, which you'll set to a dummy page.
index.html could be something like:
<html><title>Forbidden!</title><body>Nothing to see here...</body></html>
or a redirect script index.php:
<?php header('Location: /index.php'); exit(); ?>
Don't use .htaccess for blocking directory listings, it blocks access to everything.
这篇关于使用htaccess,如何限制查看目录内容,但允许服务器使用目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!