채택완료

도메인 체크하여 페이지 넘기는 소간단하게 하고 십습니다.

2014-12-09 (화) 14:36:40 5,462

도메인 체크하여 페이지 넘기는 소간단하게 하고 십습니다. 

도메인을 체크하여 "domain/index.html"페이지로 넘길려고 하는데 아래소스로 하면은 넘 복잡한거 같아서 질문올립니다.

더 간단한 방법있스시면 알려세요 감사합니다.

<?php

switch ($_SERVER["HTTP_HOST"])

{

case "aaa.com":

header("location:domain/index.html");

break;

case "www.aaa.com":

header("location:domain/index.html");

break;

case "bbb.com":

header("location:domain/index.html");

break;

case "www.bbb.com":

header("location:domain/index.html");

break;

case "ccc.com":

header("location:domain/index.html");

break;

case "www.ccc.com":

header("location:domain/index.html");

break;

case "ddd.com":

header("location:domain/index.html");

break;

case "www.ddd.com":

header("location:domain/index.html");

break;

case "eee.com":

header("location:domain/index.html");

break;

case "www.eee.com":

header("location:domain/index.html");

break;

case "fff.com":

header("location:domain/index.html");

break;

case "www.fff.com":

header("location:domain/index.html");

break;

}?> 

답변 1개 / 댓글 2개

채택된 답변
+20 포인트

아래 처럼 작성하시면 소스가 겁나게 짧아 지겠네요 ㅎㅎㅎ

$domain_array = array("aaa.com"=>"//www.naver.com","www.aaa.com"=>"//daum.net","bbb.com"=>"//sir.co.kr");
$zzz = $domain_array["{$_SERVER['HTTP_HOST']}"];
if (array_key_exists($_SERVER["HTTP_HOST"], $domain_array)) {
  header("location:$zzz");

답변에 대한 댓글 2개

감사합니다.
2014-12-09 (화) 16:13:00
테스트 해 보느라 소스가 뒤죽박죽 된것을 그대로 올렸네요.
$zzz 부분을 if문 맨 위에 위치시키세요 ^^

답변을 작성하려면 로그인이 필요합니다.