We are working on an AEM dispatcher configuration, and are trying to correctly configure our ErrorDocument settings in conjunction with rewrite rules. In short - it's unclear whether ErrorDocument will run through rewrite rules or be processed instead of them.
We have a multi-tenant configuration on the dispatcher, with each vhost normalizing inbound requests to the correct path on the publisher. We are seeing our 404 errors redirected (301'ed) to the 404 page rather than it displaying it with a 404 response. (We don't see a 404 at the browser at all).
Side note: this is a recent issue because of changes we made to the dispatcher rewrite rules, so we believe the ErrorDocument is being rewritten, but are looking for confirmation as our SDLC is kind of slow.
<IfModule disp_apache2.c>
DispatcherUseProcessedURL 1
DispatcherPassError 1
</IfModule>
Define CONTENT_ROOT /content/tenant
ErrorDocument 404 /content/tenant/404.html
RewriteMap lc int:tolower
# 301 requests coming to the document root or with .html
RewriteCond %{REQUEST_URI} ^/content/tenant/(.+)\.html$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/content/tenant/(.+) [NC,OR]
RewriteCond %{REQUEST_URI} ^/(.+)\.html$ [NC]
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/${lc:%1} [R=301,QSA,L]
# Now we have a clean URL, we need to map it to the document root
RewriteRule ^/(.+)$ ${CONTENT_ROOT}/${lc:$1}.html [L,PT,QSD]
The issue we're seeing is that the 404 document is already written to the correct path. Should we be using ErrorDocument 404 /404
instead to prevent rewrite rules from 301'ing it (as it would above) -- or does ErrorDocument happen instead of other rules?