# 如何设置不存在的页面重定向

**URL:** <https://meta.discourse.org/t/how-to-make-a-redirect-from-non-existent-pages/402807>\
**Category:** Self-hosting\
**Created:** [2026年五月12日 18:30 UTC](https://meta.discourse.org/t/how-to-make-a-redirect-from-non-existent-pages/402807 "2026-05-12T18:30:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vsekraski](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsekraski/32/553869_2.png) [@Vsekraski](https://meta.discourse.org/u/Vsekraski)\
**Post date:** [2026年五月12日 18:30 UTC](https://meta.discourse.org/t/how-to-make-a-redirect-from-non-existent-pages/402807/1 "2026-05-12T18:30:30Z")

</div>

当用户访问不存在的页面时，会显示错误信息：“错误。该页面不存在或对公众隐藏。”是否可以将用户从此类页面重定向到目标页面？

---

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [2026年五月12日 18:58 UTC](https://meta.discourse.org/t/how-to-make-a-redirect-from-non-existent-pages/402807/2 "2026-05-12T18:58:12Z")

</div>

试试这个：

> [@How to Redirect all 404 pages to home?](https://meta.discourse.org/t/how-to-redirect-all-404-pages-to-home/235187/15?u=merefield):
>
> You can handle all broken 404 pages to the home page or another page using the “Customize” feature. Go to the section Customize \> Themes \> Create New Theme \> name your theme ex 404 Redirect and set the Base Theme to Default. Then create the new theme \> Edit CSS/HTML. In the HTML section, create a JavaScript snippet that will handle the redirection. Past this code. \<script type="text/discourse-plugin"\> api.onPageChange((url, title) =\> { // Redirect to the home page for all 404 pages …

---

<div class="post-metadata">

**Author:** ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)\
**Post date:** [2026年五月12日 23:47 UTC](https://meta.discourse.org/t/how-to-make-a-redirect-from-non-existent-pages/402807/3 "2026-05-12T23:47:28Z")

</div>

另外，@Vsekraski，你不需要在每个主题中都添加 #horizon-theme 标签，除非你的问题或反馈是专门关于 Horizon 主题的。

---

<div class="post-metadata">

**Author:** ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)\
**Post date:** [2026年五月13日 08:55 UTC](https://meta.discourse.org/t/how-to-make-a-redirect-from-non-existent-pages/402807/4 "2026-05-13T08:55:44Z")

</div>

您还可以使用 #permalinks 重定向特定链接。

例如，`myforum.com/testing` 现在会引导我前往 `myforum.com/admin`。

 ![Screenshot_20260513_105121_Firefox](https://global.discourse-cdn.com/meta/original/4X/f/2/a/f2a67ae284f11343cda0146e82340f68c4801ccf.jpeg)
