'directoryindex'에 해당되는 글 1건

  1. 2009.01.09 apache DirectoryIndex 란?

apache DirectoryIndex 란?

ITWeb/서버관리 2009. 1. 9. 15:42
출처 : http://httpd.apache.org/docs/2.0/mod/mod_dir.html

DirectoryIndex 지시어

설명: 클라이언트가 디렉토리를 요청할때 찾아볼 자원 목록
문법: DirectoryIndex local-url [local-url] ...
기본값: DirectoryIndex index.html
사용장소: 주서버설정, 가상호스트, directory, .htaccess
Override 옵션: Indexes
상태: Base
모듈: mod_dir

DirectoryIndex 지시어는 클라이언트가 디렉토리명 끝에 /를 붙여서 디렉토리의 index를 요청할때 찾아볼 자원 목록을 지정한다. Local-url은 요청한 디렉토리에 상대적인 문서의 (%로 인코딩된) URL이다. 보통은 디렉토리에 있는 파일명이다. 여러 URL을 지정할 수 있고, 이 경우 서버는 첫번째로 찾은 파일을 보낸다. 자원을 찾을 수 없고 Indexes 옵션을 설정하였다면 서버는 직접 디렉토리 목록을 만든다.

예제

DirectoryIndex index.html

이 경우 http://myserver/docs/를 요청할때 http://myserver/docs/index.html이 있으면 이를 보내고, 없다면 디렉토리 목록을 보낸다.

문서가 반드시 디렉토리에 상대적일 필요는 없다.

DirectoryIndex index.html index.txt /cgi-bin/index.pl

이 경우 디렉토리에 index.html이나 index.txt가 없으면 CGI 스크립트 /cgi-bin/index.pl을 실행한다.


----------> 여기서 부터는 나의 해석.. ㅋ
그럼 이넘이랑..
RewirteRule ^/$   /index.html [R]
RewirteRule ^/$   /index.html [L]
이거랑 뭐가 다를까?
그리고 둘다 넣었을 경우 어떻게 응답을 할까?

우선 apache 에서는 RewriteRule 이 먼저 적용 된다.
이넘 들 실행 후에 암것도 없거나 그러면.. DirectoryIndex 를 찾는다..
어떤 경우에.. 파일 지정을 하지 않았거나 / 로 끝났을 경우에..

[R] 은.. access 로그를 보면 알겠지만.. request 두번 (302 한번, 200 한번)
[L] 은 access 로그에 처음 요청 URL 한번

그럼 이 [R], [L] 이건 또 뭐야??
아파치 문서에는 이렇게 되어 있다..

출처 : http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

'redirect|R [=code]' (force redirect)
Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPORARILY) will be returned. If you want to use other response codes in the range 300-400, simply specify the appropriate number or use one of the following symbolic names: temp (default), permanent, seeother. Use this for rules to canonicalize the URL and return it to the client - to translate ``/~'' into ``/u/'', or to always append a slash to /u/user, etc.
Note: When you use this flag, make sure that the substitution field is a valid URL! Otherwise, you will be redirecting to an invalid location. Remember that this flag on its own will only prepend http://thishost[:thisport]/ to the URL, and rewriting will continue. Usually, you will want to stop rewriting at this point, and redirect immediately. To stop rewriting, you should add the 'L' flag.

  • 'last|L' (last rule)
    Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/') to a real one, e.g., '/e/www/'.
  • 그렇군.. 뭔 말인지 알지?? ^^;; ㅋ
    뭐 말 그대로 인고.. redirect 근데 이넘은.. URL 도 같이 변경이 되고..
    last 는 기냥.. 여기서 그만.. 더 이상 하위 rule 은 실행을 하지 않는 다는 의미 이지요..
    그럼 이넘은.. 왜 R 처럼 URL 이 바뀌지는 않는 걸까? 설명에 있잖아..

    ㅎㅎ 그럼.. 이건 여기서 이제 그만.. ㅎㅎ

    :