ErrorDocument not working with .htaccess file
I am trying to use a .htaccess file to setup specific behaviors for one directory.
My .htaccess is as follows:
ErrorDocument 401 /var/www/secret/logging.php
AuthName "My Password Protected Site"
AuthUserFile /var/www/secret/.htpasswd
AuthType Basic
Require valid-user
# Set REMOTE_USER env variable on 401 ErrorDocument
RewriteEngine On
RewriteBase /secret/
RewriteCond %{ENV:REDIRECT_STATUS} ^401$
RewriteRule .* - [E=REMOTE_USER:%{ENV:REDIRECT_REMOTE_USER}]
However, when attempting to test this, the Apache default error page states a 404 was encountered while trying to use an ErrorDocument to handle the request. All permissions are correct, all filepaths are correct.
What am I doing wrong?
As you want to redirect to an external URL to handle the problem/error
as the documentation https://httpd.apache.org/docs/2.2/en/mod/core.html#errordocument
You have to set an URL:
ErrorDocument 401 /secret/logging.php
else the error redirection will try to go to http://{yourSite}/var/www/secret/logging.php
which doesn't exist and trigger a 404 not found error