问题原文
原帖链接 · 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:
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
