htaccess로 디렉토리 목록 거부
: 나는 폴더, 예를 들어이 /public_html/Davood/예를 들어, 폴더에 너무 많은 하위 폴더를 : /public_html/Davood/Test1/, /public_html/Davood/Test1/Test/, /public_html/Davood/Test2/, ...
/public_html/Davood/디렉토리 목록 /Davood및 하위 폴더 를 거부하려면 htaccess 파일을 추가하고 싶습니다. 가능합니까?
옵션-색인 은 디렉토리 목록을 방지하기 위해 작동해야합니다.
.htaccess 파일을 사용하는 경우 기본 아파치 구성 파일 에 "allowoverride options"설정이 있는지 확인하십시오 .
.htaccess해당 디렉토리 의 파일에 이것을 추가해보십시오 .
Options -Indexes
이것은 더 많은 정보가 있습니다.
경우 Options -Indexes브라이언 Drewery 제안대로 작동하지 않습니다, 당신은 빈의 index.php 파일을 생성하는 재귀 적 방법을 작성할 수 있습니다.
보호하고 싶은 기본 폴더 안에 넣으십시오. 어떤 이름이든 지정할 수 있습니다 (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 파일은 쉽게 삭제하거나 덮어 쓸 수 있으며 디렉토리가 나열되지 않도록합니다.
금지 된 오류를 표시하려면 .htaccess 파일에 다음 행을 포함하십시오.
Options -Indexes
파일을 색인화하고 몇 가지 정보와 함께 표시하려면 다음을 사용하십시오.
IndexOptions -FancyIndexing
특정 확장을 표시하지 않으려면 다음을 수행하십시오.
IndexIgnore *.zip *.css
옵션-인덱스 는 나에게 완벽하게 작동합니다.
다음은 .htaccess파일입니다.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes <---- This Works for Me :)
</IfModule>
....etc stuff
</IfModule>
이후 :
Options -Indexes
디렉토리 색인 목록을 허용하지 않으려는 현재 디렉토리에 .htaccess 파일을 만들어야합니다. 그러나 .htaccess 코드의 재귀에 대해 몰라 죄송합니다.
시도 해봐.
두 가지 방법이 있습니다.
.htaccess 사용 :
Options -Indexes빈 index.html 만들기
그것에 동의 해
Options -Indexes
should work if the main server is configured to allow option overrides, but if not, this will hide all files from the listing (so every directory appears empty):
IndexIgnore *
Options -Indexes returns a 403 forbidden error for a protected directory. The same behaviour can be achived by using the following Redirect in htaccess :
RedirectMatch 403 ^/folder/?$
This will return a forbidden error for example.com/folder/ .
You can also use mod-rewrite to forbid a request for folder.
RewriteEngine on
RewriteRule ^folder/?$ - [F]
If your htaccess is in the folder that you are going to forbid , change RewriteRule's pattern from ^folder/?$ to ^$ .
참고URL : https://stackoverflow.com/questions/5932641/deny-directory-listing-with-htaccess
'Programing' 카테고리의 다른 글
| Javascript의 MSIE 및 addEventListener 문제? (0) | 2020.09.18 |
|---|---|
| SQLAlchemy 식에서 컴파일 된 원시 SQL 쿼리를 가져 오는 방법은 무엇입니까? (0) | 2020.09.18 |
| Rails 콘솔에서 FactoryGirl의 팩토리를 사용하는 방법 (0) | 2020.09.18 |
| 임의의 문자열에서 유효한 Windows 파일 이름을 만드는 방법은 무엇입니까? (0) | 2020.09.18 |
| Oracle 데이터베이스에서 임시 테이블을 어떻게 생성합니까? (0) | 2020.09.18 |

