如何将所有 404 页面重定向到 nginx 中的同一个 URL?
How to redirect all 404 pages to the same URL in nginx?
我在 nginx 中设置了一个 404 页面 error_page 404 /404.php;
所以如果我去 website.com/some-bad-url
我会看到内容表单 404.php
我的问题是如何让 website.com/some-bad-url
直接从 nginx 重定向到 404.php
并让浏览器直接显示 404.php
页面?
有什么想法吗?
error_page
指令通常会执行内部重定向。如果你指定了一个scheme和一个服务器名,它会执行一个外部重定向,但是显然只能使用3xx响应代码。
例如:
error_page 404 $scheme://$host/404.php;
详情见this document。
我在 nginx 中设置了一个 404 页面 error_page 404 /404.php;
所以如果我去 website.com/some-bad-url
我会看到内容表单 404.php
我的问题是如何让 website.com/some-bad-url
直接从 nginx 重定向到 404.php
并让浏览器直接显示 404.php
页面?
有什么想法吗?
error_page
指令通常会执行内部重定向。如果你指定了一个scheme和一个服务器名,它会执行一个外部重定向,但是显然只能使用3xx响应代码。
例如:
error_page 404 $scheme://$host/404.php;
详情见this document。