Apache:重定向 404 和 ErrorDocument 404 的区别

Doc*_*iki 7 linux redirect errordocument http-status-code-404 apache-2.2

我想用 Apache 进行 404 重定向,我找到了几种解决方案:

  1. .htaccess 方法。但如果没有必要,我不想添加 .htaccess。

  2. 虚拟主机方法:

<VirtualHost *:80>
    ServerAlias *.example.com
    Redirect 404 /index.html
    ErrorDocument 404 /index.html
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

我想知道 Redirect 404 和 ErrorDocument 404 有什么区别?

qua*_*nta 12

你用Redirect指令测试了吗?

Redirect 404 /index.html意味着 404 响应将在客户端请求时返回/index.html(即使它可能存在)。

ErrorDocument 404 /index.html 意味着当客户端访问一个不存在的 URL 时,Apache 将重定向到 index.html 页面。

ErrorDocument在这种情况下,您必须使用。