작성일 : 15-04-11 13:02
|
[Script] test.co.kr 로 접속시 www.test.co.kr 로 포워딩 [url 에 www 추가]
|
|
|
글쓴이 :
조형래
 조회 : 3,298
|
도메인 접속을 무조건 www를 붙여서 접속하고자 할때
//php
if(substr($_SERVER[HTTP_HOST],0,3) != "www") {
header("location:http://www.$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");// 도메인 접속을 무조건 www를 붙여서 접속하고자 할때
}
http://www.domain.co.kr 과 http://domain.co.kr 두개 모두를 http://domain.co.kr 으로 통일하려고 할때는
도메인 접속을 www를 빼고 처리하고자 할때
if(substr($_SERVER[HTTP_HOST],0,3) == "www") {
$no_www = substr($_SERVER[HTTP_HOST],4);
header("location:http://$no_www"); // 도메인 접속을 www를 빼고 처리하고자 할때
}
// javascript
<script language="JavaScript" type="text/javascript">
var host = location.host.toLowerCase();
var currentAddress = location.href;
if (host.indexOf("www") == -1)
{
currentAddress = currentAddress.replace("//","//www.");
location.href = currentAddress;
}
</script>
|
|