코드이그나이터(CI)를 사용할 때 주소에 index.php를 제거하고 싶다면

예>

http://okkks.tistory.com/index.php/board/1

주소를 다음과 같이 사용하고 싶다면

http://okkks.tistory.com/board/1

 

 

httpd.conf 설정

apache 모듈중 mod_rewrite 사용하기

- httpd.conf 파일을 열어서 mod_rewrite.so 모듈을 사용할 수 있게 주석을 제거한다.(만약 모듈이 없다면 설치를 해야 한다.)

]# vi /usr/local/apache2/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so

 

.htaccess 파일 사용하기 위한 httpd.conf 설정

AllowOverride None <- 변경 전

AllowOverride All <- 변경 후

 

설정을 마친 후 apache를 다시 시작한다.

]# service httpd restart

 

 

ci config.php 설정

- ci 설정 파일인 config.php 파일을 열어서 $config['index_page'] 값을 없앤다.

$config['index_page'] = 'index.php'; <- 변경 전

$config['index_page'] = ''; <- 변경 후

 

 

.htaccess 설정

- 이 파일은 ci index.php 와 같은 경로에 둔다.(.htaccess 파일이 없으면 만든다.)

설정 내용>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|images|captcha|data|include|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

 

참고>

RewriteCond $1 !^(index\.php|images|captcha|data|include|uploads|robots\.txt)

-> index.php 포함,  하위 디렉토리 중 images, captcha, 생략... 등등은 index.php를 주소에서 없애지 않는다.

 

 

 

 

추가로 디렉토리를 만들고 만든 디렉토리도 index.php를 주소에서 없애고 싶지 않다면

위 문구에 추가하면 된다. ( 생략...|uploads|추가 디렉토리|robots\.txt )

 

 

설정을 마친 후 테스트를 해본다.

 

- 끝 -

 

 

403 Forbidden 에러가 발생했다면

 

.htaccess 파일 권한을 확인해 본다.

]# ls -al

권한 변경

]# chmod 755 .htaccess

또는 644

 

apache 설정을 httpd-vhosts.conf를 이용한다면 수정을 한다.

]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

- 생략 -

    <Directory "/wwwdata/okkks.tistory.com">
        Options +FollowSymLinks -Indexes +ExecCGI
        AllowOverride All
            Order allow,deny
        Allow from all
    </Directory>

- 생략 -

 

 

 

CodeIgniter 설치

- ci 설치 - CodeIgniter / 코드이그나이터

Posted by 은둔고수