2016년 3월 6일 일요일

자바스크립트 jQuery 메타태그 PHP .htaccess 사이트 리디렉션 방법

사이트 리디렉션(리다이렉션) 하는 방법

예전 홈페이지 주소로 유입되는 방문자를 신규 홈페이지로 이동시키고자할 때 사이트 리디렉트 처리하는 방법이다.
티스토리 블로그주소를 변경하였을때 응용하면 아주 유용할 것이다.

1. 자바스크립트로 리디렉션
<script type="text/javascript">
var r_url = "http://itrooms.tistory.com/";
window.location.replace(r_url);
</script>
서브도메인만 변경해서 이동시키려면 치환해서 넘겨주면된다.
r_url = r_url.replace('이전서브도메인', '신규서브도메인');

2. jQuery 리디렉션
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {
var r_url = "http://itrooms.tistory.com/";
$( location ).attr("href", r_url);
});
</script>

3. 메타 태그로 리디렉션
<meta http-equiv="refresh" content="0; url=http://itrooms.tistory.com/" />
content 안에 0은 초단위이고 3초 뒤에 이동시키려면 3을 적어주면 된다.

4. PHP 리디렉션
<?php
header('Location: http://itrooms.tistory.com/', true, 301);
exit();
?>
PHP는 서버단에서 처리되므로 HTTP 301 Moved Permanently status code 로 리디렉션이 가능하다.

5. .htaccess 리디렉션
Redirect 301 / http://itrooms.tistory.com/
아파치 httpd.conf 에서 사용할 수도 있고 .htaccess 에서도 가능하다.
HTTP 301 Moved Permanently status code 로 리디렉션이 가능

출처 : http://itrooms.tistory.com/97

댓글 없음:

댓글 쓰기