CI 묻고 답하기

제목 서브디렉토리 설치 시 .htaccess 설정 방법
카테고리 CI 2, 3
글쓴이 정수리 작성시각 2024/05/24 11:50:10
댓글 : 4 추천 : 0 스크랩 : 0 조회수 : 1358   RSS

포럼 내에서 서브 폴더에 ci 설치했을 시 .htaccess를 설정하는 글을 참조하여 설치는 하였습니다.

https://cikorea.net/bbs/view/lecture?idx=7130#google_vignette

 

테스트 시 위의 글이 적용되는 경우는 서브폴더에 index.php, .htaccess가 위치하고 있으면 정상적으로 적용이됩니다.

root

    서브
         application
         system
         index.php

         .htaacess 

 

저는 index.php, .htaccess 파일을 서브폴더 밑 public_html 폴더 밑에 위치한 환경에서 설치를 테스트를 해보았습니다.

아파치 설정: 

Alias  /sub "D:\programs\company_code\mydomain\sub\public_html"

DocumentRoot "D:\programs\company_code\mydomain"

<Directory "D:\programs\company_code\mydomain">
root

  서브
    
      public_html
            application
            system
            public_html
             index.php
             .htaccess

local/sub, local/sub/index.php/welcome 접속 시 welcome 페이지는 정상적 출력 되는것확인하였습니다.

local/sub/welcome을 하면 Internal Server Error mod_rewrite 에러가 출력이 됩니다.

아파치에 mod_rewrite log 설정 후 확인해보니

 strip per-dir prefix: D:/../company_code/mydomain/sub/public_html/welcome -> welcome
applying pattern '^(.*)$' to uri 'welcome'
 RewriteCond: input='welcome' pattern='!^(index\\.php)' => matched
RewriteCond: input='D:/../company_code/mydomain/sub/public_html/welcome' pattern='!-f' => matched
RewriteCond: input='D:/../company_code/mydomain/sub/public_html/welcome' pattern='!-d' => matched
 rewrite 'welcome' -> 'index.php/welcome'
[add per-dir prefix: index.php/welcome -> D:.../company_code/mydomain/sub/public_html/index.php/welcome
strip document_root prefix: D:/.../company_code/mydomain/sub/public_html/index.php/welcome -> /sub/public_html/index.php/welcome
internal redirect with /sub/public_html/index.php/welcome [INTERNAL REDIRECT]


[authz_core:debug]...: authorization result of Require all granted: granted
[authz_core:debug]...: authorization result of <RequireAny>: granted
add path info postfix: D:/.../company_code/mydomain/sub/public_html/public_html -> D:/\xea\xb0\x9c\xeb\xb0\x9c\xed\x94\x84\xeb\xa1\x9c\xea\xb7\xb8\xeb\x9e\xa8/company_code/mydomain/sub/public_html/public_html/index.php/welcome
//여기 public_html이 2개씩 붙는지 이해가 되지 않습니다.
strip per-dir prefix: D:/...8/company_code/mydomain/sub/public_html/public_html/index.php/welcome -> public_html/index.php/welcome 
applying pattern '^(.*)$' to uri 'public_html/index.php/welcome'
RewriteCond: input='public_html/index.php/welcome' pattern='!^(index\\.php)' => matched *여기에서 non-matched가 안뜸
 RewriteCond: input='D:/.../company_code/mydomain/sub/public_html/public_html' pattern='!-f' => matched
RewriteCond: input='D:/.../company_code/mydomain/sub/public_html/public_html' pattern='!-d' => matched
rewrite 'public_html/index.php/welcome' -> 'index.php/public_html/index.php/welcome' add per-dir prefix: index.php/public_html/index.php/welcome -> D:.../company_code/mydomain/sub/public_html/index.php/public_html/index.php/welcome
strip document_root prefix: D:/.../company_code/mydomain/sub/public_html/index.php/public_html/index.php/welcome -> /sub/public_html/index.php/public_html/index.php/welcome
internal redirect with /sub/public_html/index.php/public_html/index.php/welcome [INTERNAL REDIRECT]

 

위의 로그를 보시면 최초 welcome으로 접속하면 rewrite 검증 후 

redirect with /sub/public_html/index.php/welcome 리다이렉트 시킨 후 rewrite 검증을 합니다.
input='public_html/index.php/welcome' pattern='!^(index\\.php)' => matched *여기에서 non-matched가 안뜸

정규식이  !^(index\\.php) 이기에 문자열 사이 index.php를 잡지 못하고 matched 출력되고 다른 검증들도 matched가 출력되어

url이  /sub/public_html/index.php/public_html/index.php/welcome 형태로 재작성 및 리다이렉트, 검증 거치는 형태로 계속 반복되어

/sub/public_html/index.php/public_html/index.php/...../welcome 마지막에는 오류가 출력이 됩니다.

 

.htaccess에서 

#RewriteCond $1 !^(index\.php)
RewriteCond $1 !(index\.php)

문자열에서 index.php를 찾도록 변경해서 테스트 시 not found 출력됩니다.

 

서브폴더 / public_html / index.php, .htaccess 위치 시

.htacess를 어떻게 수정하셨을까요?

 

 다음글 CI3 세션쿠키 생성 문제 (3)
 이전글 ci4 이제 시작했습니다. 경로 질문 (2)

댓글

darkninja / 2024/05/24 22:00:34 / 추천 0

사용하시는 완전한  .htaccess 파일을 올려주셔야 답변이 달리지 않을까요?

정수리 / 2024/05/27 09:08:49 / 추천 0

@darkninja

답변감사합니다

위의 링크에 올려져있는 .htaccess 코드를 사용하고 있어서 제가 변경하면서 테스트한 부분만 올렸습니다.

아래가 완전한 .htaccess파일 내용입니다.

RewriteEngine On

#RewriteCond %{REQUEST_URI} !^(/index\.php) 
#RewriteCond $1 !(index\.php)
RewriteCond $1 !^(index\.php)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
 
RewriteRule ^(.*)$ index.php/$1 [L]

 $config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
 $config['base_url'] .= "://" . $_SERVER['HTTP_HOST'];
 $config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);

$config['index_page'] = '';

 

darkninja / 2024/05/27 22:38:37 / 추천 0
htaccess 파일에 RewriteBase 만  추가하시면 될거 같네요.
ci4 버젼에 있는 htaccess 파일에 RewriteBase 만 수정하여 사용가능할 겁니다.

자꾸 한가지씩 빠뜨리네요...
저의 아파치 설정은 
DocumentRoot "d:/htdocs"
<Directory "d:/htdocs"> 이렇게 되어 있습니다. 여기에서 문제가 발생하지 않았을까요?


	# If you installed CodeIgniter in a subfolder, you will need to
	# change the following line to match the subfolder you need.
	# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
	# RewriteBase /
	RewriteBase /sub/public_html/

#RewriteCond %{REQUEST_URI} !^(/index\.php)
#RewriteCond $1 !(index\.php)
RewriteCond $1 !^(index\.php)
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
  
RewriteRule ^(.*)$ index.php/$1 [L]

 

정수리 / 2024/05/28 09:51:59 / 추천 0

@darkninja

감사합니다.

RewriteBase로 경로설정만 해주면되는거였군요

덕분에 해결하지 못했던 일을 해결하게 되었습니다.