https://domainA.org에서 https://DomainB.com으로 자동 리다이렉트
작성자 정보
- 관리자 작성
- 작성일
컨텐츠 정보
- 279 조회
- 목록
본문
웹사이트 방문자를 https://domainA.org에서 https://DomainB.com으로 자동 리다이렉트 시키는 코드는 사용하는 서버나 프론트엔드 기술에 따라 달라질 수 있습니다. 아래는 가장 일반적으로 사용되는 리디렉션 코드 예시 3가지입니다:
1. HTML 메타 태그 방식 (간단한 방법)
<!-- index.html 혹은 메인 페이지 <head> 안에 삽입 -->
<meta http-equiv="refresh" content="0; url=https://dominA.org">
content="0" 은 즉시 리디렉션
사용자 브라우저에서 작동
2. JavaScript 방식 (브라우저 기반 리디렉션)
<script>
window.location.href = "https://domainB.org";
</script>
<head> 또는 <body> 안에 포함 가능
자바스크립트가 활성화된 브라우저에서만 작동
3. 서버 측 리디렉션 (.htaccess for Apache)
apacheconf
# .htaccess 파일에 추가
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domainA\.org [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.domainB\.org [NC]
RewriteRule ^(.*)$ https://domainA.org/$1 [L,R=301]
Apache 서버에서 작동
301은 영구 리디렉션 (SEO에 좋음)
추가 팁:
Nginx 서버라면 아래처럼 설정합니다:
nginx
server {
listen 80;
server_name domain.org www.domain.org;
return 301 https://domain.org$request_uri;
}
필요한 환경(Apache, Nginx, HTML 등)을 알려주시면 해당 환경에 최적화된 코드로 정리가능 합니다.