【问题标题】:How to redirect all 404 pages to the same URL in nginx?如何将所有 404 页面重定向到 nginx 中的相同 URL?
【发布时间】:2017-11-19 13:56:56
【问题描述】:

我在 nginx error_page 404 /404.php; 中设置了一个 404 页面

所以如果我去website.com/some-bad-url,我会看到404.php的内容表单

我的问题是如何让website.com/some-bad-url直接从nginx重定向到404.php,并让浏览器直接显示404.php页面?

有什么想法吗?

【问题讨论】:

    标签: nginx http-status-code-404 url-redirection


    【解决方案1】:

    error_page 指令通常会执行内部重定向。如果指定方案和服务器名,会进行外部重定向,但显然只能使用 3xx 响应码。

    例如:

    error_page 404 $scheme://$host/404.php;
    

    详情请见this document。

    【讨论】:

      猜你喜欢
      • 2013-06-18
      • 2020-05-16
      • 2015-10-19
      • 1970-01-01
      • 2013-01-09
      • 1970-01-01
      • 2012-05-25
      • 2019-03-03
      • 1970-01-01
      相关资源
      最近更新 更多