샘플 페이지의 301 리디렉션 (주소 변경, 홈페이지의 301 리디렉션)

블로그 주소 변경을 진행하려고 합니다. 구글 서치 콘솔에서 '샘플 페이지의 301 리디렉션'을 요청하지만, 301 리디렉션 코드는 서버 사이드에서 지시하는 것이므로, 티스토리와 같은 블로그에서 다른 블로그로 주소 변경은 힘든 편에 속합니다.

301 Moved Permanently
이 응답 코드는 요청한 리소스의 URI가 변경되었음을 의미합니다. 새로운 URI가 응답에서 아마도 주어질 수 있습니다.

그리하여 다음과 같은 임시 방편으로 스크립트를 보완해보겠습니다. 자바스크립트를 통한 클라이언트 사이드에서는 301 코드를 제어할 수 없으므로, 해당 기능이 정상적으로 작동할지는 미지수라는 단점이 있는 점을 참고해 주십시오.

샘플 페이지의 301 리디렉션
  <script>  
    var redirections = [
    {
      from: 'https://beomsang.tistory.com/entry/hangul-2010-hwpx-broken-fix',
      to: 'https://www.beomsang.com/2023/11/how-to-fix-hangeul-2010-hwpx-broken.html'
    },
    {
      from: 'https://beomsang.tistory.com/entry/how-to-use-starbucks-gifticon-is-it-possible-to-use-other-menus',
      to: 'https://www.beomsang.com/2023/12/how-to-use-starbucks-gifticon-is-it-possible-to-use-other-menu-items.html'
    },
    {
      from: 'https://beomsang.tistory.com/entry/nike-dunk-low-killer-whale-review-recommended-list-price-sizing-tips',
      to: 'https://www.beomsang.com/2023/11/nike-dunk-low-orca-review.html'
    },
    {
      from: 'https://beomsang.tistory.com/entry/what-is-the-difference-between-youtube-not-interested-and-do-not-recommend-a-channel',
      to: 'https://www.beomsang.com/2022/07/what-is-the-difference-between-not-interested-in-youtube-and-not-recommending-channels.html'
    },
    {
      from: 'https://beomsang.tistory.com/entry/%EA%B7%B8%EB%9E%98%ED%94%BD%EC%B9%B4%EB%93%9CRTX-3070-%EC%98%A4%EB%A5%98-%EC%BD%94%EB%93%9C-31-43-%ED%95%B4%EA%B2%B0-win10',
      to: 'https://www.beomsang.com/2023/11/how-to-resolve-graphics-card-rtx-3070-error-code-31-43-windows-10.html'
    }
    ];    
    for (var i = 0; i < redirections.length; i++) {
      if (window.location.href === redirections[i].from) {    
        var meta = document.createElement('meta');
        meta.httpEquiv = "refresh";
        meta.content = "0;URL=" + redirections[i].to;
        document.getElementsByTagName('head')[0].appendChild(meta);      
        break;
      }
    }
  </script>

window.location.replace(redirection.to); 코드를 통해 바로 리디렉션하는 방법도 있기는 한데, 이 코드 또한 HTTP 상태 코드 중 200(성공)을 반환하기 때문에 기대하는 효과를 얻을지는 알 수 없습니다.

    for (var i = 0; i < redirections.length; i++) {
      if (window.location.href === redirections[i].from) {    
        window.location.replace(redirection.to);        
        break;
      }
    }
댓글 쓰기
가져가실 때, 출처 표시 부탁드려요! 감사합니다. 💗