PHP AAAA.com 에서 BBBB.com 으로 이동하기 (포워딩)
페이지 정보

본문
홈페이지 운영시 도메인이 변경될때 하부 url 까지 유지하면서 변경하는 방법입니다.
이때 도메인 둘다 접속이 가능한 상태이어야 합니다.
카페24 호스팅 등의 자체도메인 aaaa.cafe24.com 등의 변경할때도 사용할 수 있습니다.
1. http:// 또는 https:// 를 유지하면서 도메인 변경하기
<?php
// 도메인 이동하기 시작 ( http:// 또는 https:// 변경없음 )
$http_forwarded_before = ""; // 변경전 도메인
$http_forwarded_after = ""; // 변경후 도메인
if(strpos($_SERVER['HTTP_HOST'],$http_forwarded_before) !== false) {
// http:// 일때
if((isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') || !(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')) {
$https_forwarded_url = "http://www.{$http_forwarded_after}".$_SERVER['REQUEST_URI'];
header("Location:{$https_forwarded_url}");
}
// https:// 일때
elseif((isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')) {
$https_forwarded_url = "https://www.{$http_forwarded_after}".$_SERVER['REQUEST_URI'];
header("Location:{$https_forwarded_url}");
}
}
// 도메인 이동하기 끝
?>
2. https://도메인으로 변경하기
<?php
// 도메인 이동하기 시작 ( https:// 로 변경 )
$http_forwarded_before = ""; // 변경전
$http_forwarded_after = ""; // 변경후
if(strpos($_SERVER['HTTP_HOST'],$http_forwarded_before) !== false) {
$https_forwarded_url = "https://www.{$http_forwarded_after}".$_SERVER['REQUEST_URI'];
header("Location:{$https_forwarded_url}");
}
// https://도메인 이동하기 끝
?>
이때 도메인 둘다 접속이 가능한 상태이어야 합니다.
카페24 호스팅 등의 자체도메인 aaaa.cafe24.com 등의 변경할때도 사용할 수 있습니다.
1. http:// 또는 https:// 를 유지하면서 도메인 변경하기
<?php
// 도메인 이동하기 시작 ( http:// 또는 https:// 변경없음 )
$http_forwarded_before = ""; // 변경전 도메인
$http_forwarded_after = ""; // 변경후 도메인
if(strpos($_SERVER['HTTP_HOST'],$http_forwarded_before) !== false) {
// http:// 일때
if((isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') || !(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')) {
$https_forwarded_url = "http://www.{$http_forwarded_after}".$_SERVER['REQUEST_URI'];
header("Location:{$https_forwarded_url}");
}
// https:// 일때
elseif((isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')) {
$https_forwarded_url = "https://www.{$http_forwarded_after}".$_SERVER['REQUEST_URI'];
header("Location:{$https_forwarded_url}");
}
}
// 도메인 이동하기 끝
?>
2. https://도메인으로 변경하기
<?php
// 도메인 이동하기 시작 ( https:// 로 변경 )
$http_forwarded_before = ""; // 변경전
$http_forwarded_after = ""; // 변경후
if(strpos($_SERVER['HTTP_HOST'],$http_forwarded_before) !== false) {
$https_forwarded_url = "https://www.{$http_forwarded_after}".$_SERVER['REQUEST_URI'];
header("Location:{$https_forwarded_url}");
}
// https://도메인 이동하기 끝
?>
댓글목록
등록된 댓글이 없습니다.