否认目录中的htaccess上市 [英] deny directory listing with htaccess
问题描述
我有一个文件夹,例如: /的public_html / Davood /
和太多的子文件夹中的文件夹,例如: /的public_html / Davood / Test1的/
, /的public_html / Davood / Test1的/测试/
, /的public_html / Davood / Test2的/
...
i have a folder, for example : /public_html/Davood/
and too many sub folder in folder, for example : /public_html/Davood/Test1/
, /public_html/Davood/Test1/Test/
, /public_html/Davood/Test2/
, ...
我想添加一个htaccess文件到 /的public_html / Davood /
要拒绝Directory上市在 / Davood
和子文件夹,这是可能的?
i want add a htaccess file into /public_html/Davood/
To deny DirectoryListing In /Davood
And Sub Folders, It's Possible ?
在此先感谢
推荐答案
如果选项-Indexes
不为布莱恩Drewery建议的工作,你可以写一个递归的方法来创建空白的index.php文件。
If Options -Indexes
does not work as Bryan Drewery suggested, you could write a recursive method to create blank index.php files.
将您希望保护这里面你的基地文件夹,你可以将其命名什么(我会建议的index.php)
Place this inside of your base folder you wish to protect, you can name it whatever (I would recommend index.php)
<?php
recurse(".");
function recurse($path){
foreach(scandir($path) as $o){
if($o != "." && $o != ".."){
$full = $path . "/" . $o;
if(is_dir($full)){
if(!file_exists($full . "/index.php")){
file_put_contents($full . "/index.php", "");
}
recurse($full);
}
}
}
}
?>
这些空白的index.php文件,可以很容易地删除或覆盖,他们会保持你的目录被可列表。
These blank index.php files can be easily deleted or overwritten, and they'll keep your directories from being listable.
这篇关于否认目录中的htaccess上市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!