아래 내용을 html 최상단에 추가합니다.
PHP 5.3 미만일때
<?php
$str = $HTTP_HOST;
if(!eregi("www",$str)) {
  header("location: http://www." . $str . $REQUEST_URI);
}
?>
또는
<?php
// PHP 5.3 미만일때
$str = $_SERVER['SERVER_NAME'];
if(!eregi("www",$str)) {
  header("location: http://www.".$str.$REQUEST_URI);
}
?>
PHP 버전에 관계없이 모두 사용 가능한 방법
<?php
$str = $_SERVER['SERVER_NAME'];
if (!preg_match('/www/', $str) == true) {
  header("location: http://www.".$str.$REQUEST_URI);
}
?>
2017/03/22 21:04 2017/03/22 21:04

Trackback Address :: https://youngsam.net/trackback/1864