아파치에서 서브도메인을 셋팅시 일일이 계정을 생성해야 함.
아파치에서 가상호스트에서 각각을 지정해야함.
<virtualhost 000.000.000.000:80>
servelname ifull.co.kr
sereralias ifull.co.kr www.ifull.co.kr
documentroot /home/ifull/public_html
</virtualhost>
기본 셋팅인데, 여기서 추가로 webhard.ifull.co.kr을 만들시에
<virtualhost 000.000.000.000:80>
servelname webhard.ifull.co.kr
sereralias webhard.ifull.co.kr
documentroot /home/ifull/public_html/webhard
</virtualhost>
이렇게 셋팅해야 한다.
그럼 이제 좀 더 편하게 셋팅하는 방법을 알아보자.
rewrite모듈사용하기
먼저, nameserver에 도메인 셋팅에 다음을 추가한다.
# vi /var/named/~~~~/ifull.co.kr.zone
*.ifull.co.kr IN A 000.000.000
다음은 아파치를 셋팅한다.
<virtualhost 000.000.000.000:80>
servelname ifull.co.kr
sereralias *.ifull.co.kr
documentroot /home/ifull/public_html
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.ifull\.co.kr
RewriteCond %{HTTP_HOST} !^ifull\.com
RewriteCond %{HTTP_HOST} !^[^.]+\.ifull\.co.kr
RewriteRule ^([^.]+)\.ifull\.co.kr(.*) http://ifull.co.kr/$1/$2
</virtualhost>
이렇게 셋팅이 되면
help.ifull.co.kr로 접속시
/hoem/ifull/public_html/help <== 이 디렉토리가 있으면 이쪽으로 넘어온다. 없으면 안나옴.
/public_html/.htaccess 를 이용해서
http://www.ifull.co.kr/123 ==> ifull.co.kr/event/123/123/123/index.php 로 보내기
#vi .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^123$ /home/ifull/public_html/123/123/123/ [L]
으로 처리 가능하다.
아이디로 처리하고 싶을 경우에는
RewriteRule ^123$ /home/ifull/public_html/123/123/123/ [L]
대신
RewriteRule ^([a-zA-Z0-9]+)$ test.php?id=$1 [L, QSA]
이런식으로 사용도 가능하다.