# 페이지를 찾을 수 없을 때 스크립트를 강제 실행하는 방법은 무엇인가요?

**URL:** https://meta.discourse.org/t/how-do-you-force-a-script-to-fire-on-page-not-found/240362
**Category:** Development
**Created:** [9월 29, 2022, 4:33오전 UTC](https://meta.discourse.org/t/how-do-you-force-a-script-to-fire-on-page-not-found/240362 "2022-09-29T04:33:25Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![markschmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markschmucker/32/141599_2.png) [@markschmucker](https://meta.discourse.org/u/markschmucker)
#### Post date: [9월 29, 2022, 4:33오전 UTC](https://meta.discourse.org/t/how-do-you-force-a-script-to-fire-on-page-not-found/240362/1 "2022-09-29T04:33:25Z")

</div>

[How do you force a script to refire on every page load in Discourse?](https://meta.discourse.org/t/how-do-you-force-a-script-to-refire-on-every-page-load-in-discourse/74856/28) 토론을 이어서:

> [@Zyniker](#):
>
> 현재 이 API를 사용하여 카테고리에서 외부 사이트로 리다이렉트를 트리거하는 방법을 시도하고 있습니다…
> 
> ```plaintext
> <script type='text/discourse-plugin' version='0.8.19'>
> $( document ).ready(function() {
> if ( window.location.href === "https://omnifora.com/c/redirect-politifora" ) {
> window.location.replace( "https://politifora.com/" );
> }
> });
> </script>
> 
> ```

이미 닫힌 해당 주제에서 논의된 바와 같이, 위 코드는 **토픽** 이 로드될 때 실행됩니다. 하지만 저는 **페이지를 찾을 수 없음(Page Not Found)** 페이지가 로드될 때 리다이렉트를 트리거하고 싶습니다. `api.onPageChange`도 `$( document ).ready`도 404 오류 시에는 실행되지 않습니다. 404를 감지하고 리다이렉트하는 방법은 무엇일까요?
