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

Apache ErrorDocument returns 404 in place of 302

· 52CE 我爱测

I have a Directory and DirectoryMatch declaration with ErrorDocument as <Directory "/Images/folder"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all ErrorDocument 404 /folder/default.jpg </Directory> Thi…

问题原文

原帖链接 · Hado99 · CC BY-SA 4.0

I have a Directory and DirectoryMatch declaration with ErrorDocument as

<Directory "/Images/folder">
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all

        ErrorDocument 404 /folder/default.jpg
</Directory>

This works fine and I get a 404 with the default image in the browser. But changing 404 to 302 still returns a 404 in place of intended 302. Only this time the default image is not returned with a 404.

I am using apache 2.2. Please advise.

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

ErrorDocument 404 /folder/default.jpg

Your explanation appears to show a misunderstanding of what this directive does. This particular directive will return /folder/default.jpg for any request (in this directory tree) that results in a 404, ie. does not exist. It defines the 404 error document.

Changing this to 302 does not make sense. You are simply removing the 404 error document (a 404 status is still returned but without the intended error document, ie. default.jpg). 3xx status are not error states, they are "redirection" states and require a corresponding Location HTTP response header.

By the sounds of it you perhaps want to "redirect" to the /folder/default.jpg image when an image that does not exist is requested? Instead of triggering a 404? For this you could specify an absolute URL (as noted by @Stephen in comments), or use mod_rewrite RewriteRule and RewriteCond. However, using the 404 error document in the conventional way would be the preferred approach here I think.

Reference:

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

资料来源与适用范围

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

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

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