使用htaccess,如何限制查看目录内容,但允许服务器使用目录? [英] Using htaccess, how to restrict seeing directory contents, but allow server to use the contents?

查看:115
本文介绍了使用htaccess,如何限制查看目录内容,但允许服务器使用目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更具体地说,我有一个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,如何限制查看目录内容,但允许服务器使用目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆