最後更新: 2020-12-18


Apache 404 errors handle ( 用 ErrorDocument, SetEnvIf )


方法1: ErrorDocument


ErrorDocument 404 "missing file"

 * 在 /var/log/httpd/error_log 依然每次有一行 log


AllowOverride 最小要有 FileInfo, 否則不能在 .htacces 用 ErrorDocument

方法2: SetEnvIf

SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...

Example 1: 不在 "access.log" 記錄有關 robots.txt 的訪問

SetEnvIf Request_URI "^/robots\.txt$" dontlog
CustomLog logs/access.log common env=!dontlog


如果 robots.txt 不存在, 那會 log 到 error.log

Example 2

SetEnvIf Request_URI \.gif$ gif-image
CustomLog gif-requests.log common env=gif-image
CustomLog nongif-requests.log common env=!gif-image

log 404 errors to access.log

ErrorLog "logs/error.log"

... File does not exist ...

ErrogLog have not support conditional.

You can send the logs to syslog or script and filter it.

Suppress them from the ErrorLog, but still have them in the access log.

# Don't log missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* - [R=404,L]


Centos 上的 welcome.conf 與 ErrorDocument


welcome.conf overwrites the ErrorDocument 403 statement in the virtual host's configuration file.

Commenting out the ErrorDocument 403 line in welcome.conf solved the issue.