http 사용자를 https로 리다이렉트 시키거나 https 사용자를 http로 리다이렉트 처리하는 사용자 함수입니다. 

<?php
 function https_redirect($ssl=false) 
 { 
   $https = array( 
     'HTTP_X_FORWARDED_PROTO' => 'HTTPS', 
     'HTTP_X_SSL' => 'ON', 
     'HTTPS' => 'ON', 
     'SSL' => 'ON' 
   ); 

   $protocol = 'https://'; 
   foreach($https as $q=>$w) 
   { 
     if(strtoupper($_SERVER[$q]) === $w) 
     { 
       $protocol = false; 
       break; 
     } 
   } 

   if($ssl === true) 
   { 
     $protocol = (false === $protocol) ? 'http://' : false; 
   } 

   if(false !== $protocol) 
   { 
     header('HTTP/1.0 301 Moved Permanently'); 
     header('Location: '.$protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); 
     die(); 
   } 
 } 

 // http 사용자를 https 로 redirect 처리 예제 
 https_redirect();

 // https 사용자를 http 로 redirect 처리 예제 
 https_redirect(true);  
 ?>

<?php 
 $redirect_domain = 'www.yoursite.com'; 

 if(isset($_SERVER['PANTHEON_ENVIRONMENT']) && $_SERVER['PANTHEON_ENVIRONMENT'] == 'live') { 
   $redirect_location = ''; 
   // Check if SSL is enabled. 
   if (isset($_SERVER['HTTP_X_SSL']) && $_SERVER['HTTP_X_SSL'] == 'ON') { 
     $redirect_location = 'http://' . $redirect_domain . $_SERVER['REQUEST_URI']; 
   } 
   // Require SSL for everything else. 
   else if (!isset($_SERVER['HTTP_X_SSL']) || $_SERVER['HTTP_X_SSL'] != 'ON') { 
    $redirect_location = 'https://' . $redirect_domain . $_SERVER['REQUEST_URI']; 
  } 

  // Perform redirect. 
  if ($redirect_location) { 
    header('HTTP/1.0 301 Moved Permanently'); 
    header('Location: ' . $redirect_location); 
    exit; 
  } 
 } 
 ?>
출처: http://helpdesk.getpantheon.com/customer/portal/articles/368354-redirecting-incoming-requests

0 댓글