大网数据广告活动
网站运营与故障问答

Have Apache show 404 at missing page URL instead of redirecting to error page URL

· 52CE 我爱测

Assuming non-existent-page.html does not exist, and the user is trying to access that page and triggered a 404 error. Can i show the requested page URL: http://www.example.com/non-existent-page.html instead of the error page URL:…

问题原文

原帖链接 · Explisam · CC BY-SA 3.0

Assuming non-existent-page.html does not exist, and the user is trying to access that page and triggered a 404 error.

Can i show the requested page URL:

http://www.example.com/non-existent-page.html

instead of the error page URL:

http://www.example.com/404.html

Solution:

While looking at Stephen Ostermiller's answer i knew i was using a relative URL, but i realized it had a missing trailing slash at the end because i was pointing to a directory and not a page. This mostly occurs with some xSP with bad configurations.

Problem

ErrorDocument 404 /error/404  <-- no slash

Fix

ErrorDocument 404 /error/404/ <-- added slash

已采纳解答

原帖链接 · Stephen Ostermiller · CC BY-SA 3.0

Apache server can be configured to show the error page at the error URL, or it can redirect to the error page. It is almost better to show the error page directly at the URL rather than redirecting to it.

The Apache ErrorDocument directive explains how to implement it both ways:

URLs can begin with a slash (/) for local web-paths (relative to the DocumentRoot), or be a full URL which the client can resolve.

In practical terms, that means if you specify the error document as an absolute URL it will cause a redirect to the error page:

ErrorDocument 404 http://www.example.com/404.html

but if you specify the error document as a relative URL starting with a slash, it will show the error document at the original URL where the error occurred:

ErrorDocument 404 /404.html

My guess is that you have your ErrorDocument directive configured as an absolute URL either in your .htaccess file or your httpd.conf file. You need to edit it to change it to a relative URL.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。