your programing

index.html을 기본값으로 설정하지만 입력하면 index.php를 방문 할 수 있습니다.

lovepro 2020. 12. 29. 08:07
반응형

index.html을 기본값으로 설정하지만 입력하면 index.php를 방문 할 수 있습니다.


.htaccess 파일에 다음 줄이 있습니다.

DirectoryIndex index.html index.php

index.php에 갈 때마다 index.html로 이동합니다. 둘 다 허용 할 수 있지만 www.domain.com을 방문하는 사용자의 경우 index.html을 기본값으로 두어야합니까?


기본적으로 DirectoryIndex는 다음과 같이 설정됩니다.

DirectoryIndex index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml

Apache는 위의 각 파일을 순서대로 찾고 방문자가 디렉토리 만 요청할 때 찾은 첫 번째 파일을 제공합니다. 웹 서버가 현재 디렉토리에서 DirectoryIndex 지시문의 이름과 일치하는 파일을 찾지 못하면 현재 디렉토리의 모든 파일을 보여주는 디렉토리 목록이 브라우저에 표시됩니다.

순서는 DirectoryIndex index.html index.php// 기본값은 index.html 이어야합니다.

참조 : 여기 .


WordPress를 사용하는 경우 이제이를 해결하기위한 필터 후크가 있습니다.

remove_filter('template_redirect', 'redirect_canonical'); 

(당신의 테마에 넣어주세요 functions.php)

이것은 WordPress에 index.php루트 페이지로 다시 리디렉션하지 않고 원래 위치에 있도록 지시합니다. 방법 그건, index.html의 기본 페이지로 할당 할 수 있습니다 .htaccess와 함께 작업 할 수 있습니다 index.php.


@TheAlpha의 수락 된 대답에 동의합니다. Apache는 DirectoryIndex 대상 파일을 왼쪽에서 오른쪽으로 읽습니다. 첫 번째 파일이 있으면 apche가 제공하고 그렇지 않으면 다음 파일이 디렉토리의 색인으로 제공됩니다. 따라서 다음 지침이있는 경우 :

DirectoryIndex file1.html file2.html

Apache는 /file.html을 색인으로 제공합니다. /file2.html을 색인으로 설정하려면 파일 순서를 변경해야합니다.

DirectoryIndex file2.html file1.html

RewriteRule을 사용하여 인덱스 파일을 설정할 수도 있습니다.

RewriteEngine on

RewriteRule ^$ /index.html [L]

위의 RewriteRule은 홈페이지를 /index.html로 재 작성할 것입니다. 재 작성은 내부적으로 발생하므로 http://example.com/ 은 index.html의 내용을 보여줍니다.


DirectoryIndex index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml

수단이 없나요? 이렇게 추가해야 할 수도 있습니다!

<IfModule dir_module>
    DirectoryIndex index.php index.html index.htm
</IfModule>

여기에 이미지 설명 입력


RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php%{QUERY_STRING} [L]

이 두 줄을 .htaccess 파일의 맨 위에 놓으십시오. .php 페이지의 URL에 .html이 표시됩니다.

RewriteEngine on
RewriteRule ^(.*)\.php$ $1.html%{QUERY_STRING} [L]

.html 페이지의 URL에 .php를 표시하는 데 사용합니다.


안녕,

글쎄, 나는 위에서 언급 한 방법을 시도했습니다! 예, 작동하지만 내가 원하는 방식은 아닙니다. 추가 조치를 통해 기본 페이지 확장 을 기본 도메인 으로 리디렉션하고 싶었습니다 .

여기 내가 어떻게 ...

# Accesible Index Page
<IfModule dir_module>
 DirectoryIndex index.php index.html
 RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(html|htm|php|php3|php5|shtml|phtml) [NC]
 RewriteRule ^index\.html|htm|php|php3|php5|shtml|phtml$ / [R=301,L]
</IfModule>

위의 코드는 단순히 index. *를 캡처하여 기본 도메인으로 리디렉션합니다.

감사합니다

참조 URL : https://stackoverflow.com/questions/10002439/make-index-html-default-but-allow-index-php-to-be-visited-if-typed-in

반응형