2차주소를 구입하여 설정해도, tibyte.tistory.com과 같은 주소로 접속하면
주소창의 주소가 2차주소가 아닌 1차주소로 보여지게 됩니다.

<head>태그나 <body>태그 안에 아래와 같은 자바스크립트를 추가하면 1차주소로 접속했을 때 
자동으로 2차주소로 바뀌게 할 수 있습니다.


<script language = javascript>

var url1 ='1차주소';
var url2 ='2차주소';
if(document.URL.match(url1)) document.location.href = document.URL.replace(url1, url2);

</script>


변수 url1에  1차주소를,
변수 url2에  2차주소를 지정합니다.
match 함수를 사용하여 URL이 url1을 포함하고 있는지 검사하고, 있으면, 기존주소에서  url1과 같은 부분을 url2로 치환한 주소를 현재 주소로 합니다.



아래는 사용예시입니다.
===================================================================================================
<script language = javascript>

var url1 ='tibyte.tistory.com';
var url2 ='www.tibyte.kr';
if(document.URL.match(url1)) document.location.href = document.URL.replace(url1, url2);

</script>
==================================================================================================





copyright(C)www.tibyte.kr

+ Recent posts