호스팅하나 도메인별 다른 페이지 접속 - 다중도메인

300x250

호스팅 하나에 몇개의 도메인을 다른 페이지로 접속 하게 할 수 있습니다.

Apache서버를 직접 운영한다면 virtual host 를 이용해서 도메인별 접속 경로를 지정 할 수있지만 구매한 호스팅을 이용한다면 virtual host 이용이 불가능 합니다.


호스팅 업체별로 하나의 호스팅에 몇개의 도메인 연결이 가능한데요 물론 호스팅 업체에서 각각 다른 경로를 지정해주는 경우도 없습니다.


하지만 모든 도메인이 하나의 index.html 파일로 연결 된다는 가정하에 각각 도메인 별 접속경로를 다르게 하는 방법을 소개하려 합니다.


과제 : 하나의 호스팅이 몇개의 도메인 연결이 가능 하지만 모든 도메인이 하나의 index.html 파일로 연결되는 경우 도메인 별 각각 다른 경로의 index.html 파일로 접속 되게 만들기.


먼저 도메인은 총 3개입니다.


aaa.com

bbb.com

ccc.com

이렇게 도메인 3개일 경우 aaa.com 은 /aaa/index.html 로 연결 하고 bbb.com 은 /bbb/index/html 로 연결 ccc.com 은 /ccc/index.html 로 연결 되어야 한다면 다음과 같이 설정 하면 됩니다.


가장 먼저 최상위에 index.php 파일을 하나 만들어 줍니다.



<?

if ($_SERVER[HTTP_HOST]=="aaa.com") { $index="index1.php"; }  

elseif ($_SERVER[HTTP_HOST]=="www.aaa.com") { $index="index1.php"; }  

elseif ($_SERVER[HTTP_HOST]=="bbb.com") { $index="index2.php"; }

elseif ($_SERVER[HTTP_HOST]=="www.bbb.com") { $index="index2.php"; }

elseif ($_SERVER[HTTP_HOST]=="ccc.com") { $index="index3.php"; }

elseif ($_SERVER[HTTP_HOST]=="www.ccc.com") { $index="index3.php"; }


?>


<? include $index; ?>


이렇게 index.php 파일을 하나 만들어서 호스팅 root 에 업로드 합니다.


이제 각각의 php 파일을 하나씩 만들어 줍니다.

index1.php >> aaa.com 

index2.php >> bbb.com

index3.php >> ccc.com

으로 연결을 설정 합니다.


index1.php 파일에는 

<? 

      echo("<script>location.href="/aaa/index.html';</script>"); 

?> 


index2.php 파일에는 

<? 

      echo("<script>location.href="/bbb/index.html';</script>"); 

?> 


index3.php 파일에는 

<? 

      echo("<script>location.href="/ccc/index.html';</script>"); 

?> 


이렇게 만들어 줍니다 index1.php , index2.php, index3.php 파일을 html 파일로 만들수도 있는데요 이경우 mata 태그를 이용하시면 됩니다. html 이나 php 파일이나 상관 없습니다.


<meta http-equiv="refresh" content="0;url=/ aaa/index.html">


이렇게 만들었다면 index.php 파일과 동일한 위치에 index1.php , index2.php , index3.php 파일을 업로 드 해줍니다.



이제 테스트 해보시면 

aaa.com 으로 접속하면 /aaa/index.html 로 접속 하고 bbb.com 으로 접속하면 /bbb/index.html 로 접속 하는 것을 확인 하실 수 있습니다.


그런데 요기서 문제가 하나 있습니다.


aaa.com 으로 접속을 하면 도메인 주소 줄이 http://aaa.com/aaa/index.html  이렇게 표기 됩니다.

도메인 주소가 보기 싫죠 ..

도메인 주소에 오로지 http://aaa.com 만 나오게 변경하는게 더욱 깔끔합니다.

그러면 index1.php, index2.php, index3.php 파일을 변경해야 합니다. 

해당 파일일 모두 html 파일로 새롭게 만들어 줍니다.


파일의 내용은 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="{Context::getLangType()}" xmlns="http://www.w3.org/1999/xhtml">

   <head>

       <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

       <meta name="keywords" content="">

       <meta name="description" content="">

       <meta name="author" content="">

       <title>홈페이지이름</title>

   </head>

   <frameset rows="0%,100%" cols="*" border="0" framespacing="0">

       <frame src=" scrolling="NO" frameborder="NO" name="no">

       <frame src="/aaa/index.html" frameborder="NO" name="main" marginwidth="0" marginheight="0" scrolling="auto">

   </frameset>

   <noframes>

   </noframes>

    <body>

   </body>

</html>


위 내용에서 붉은색을 표기 된 부분을 수정해서 index1.htm , index2.html , index3.html 파일을 만들어 줍니다. 
그리고 이전과 동일하게 index.php 파일과 같은 경로에 업로드 해줍니다.

그리고 index.php 파일도 수정해야 하는데요 


<?

if ($_SERVER[HTTP_HOST]=="aaa.com") { $index="index1.html"; }  

elseif ($_SERVER[HTTP_HOST]=="www.aaa.com") { $index="index1.html"; }  

elseif ($_SERVER[HTTP_HOST]=="bbb.com") { $index="index2.html"; }

elseif ($_SERVER[HTTP_HOST]=="www.bbb.com") { $index="index2.html"; }

elseif ($_SERVER[HTTP_HOST]=="ccc.com") { $index="index3.html"; }

elseif ($_SERVER[HTTP_HOST]=="www.ccc.com") { $index="index3.html"; }


?>


<? include $index; ?>


위과 같이 php 확장자를 html 로 변경하시면 됩니다.


그럼 테스트 해보시면 기존에 http://aaa.com/aaa/index.html 로 표기 되는 주소줄이 http://aaa.com 으로 표기 되는 것을 확인 하실 수 있습니다.



300x250
이글에는 개 의 댓글이 있습니다. 댓글 확인 ▼

Comments