Apache – ErrorLog Cannot Use Full URL in 401 ErrorDocument

.htaccessApache2

I use the .htaccess file on my Apache to display custom error documents. This all works fine too.

But I still see lots of this error in the log:

[Thu Aug 13 10:38:31 2020] [notice] [client AH00113: /home/www/.htaccess:6 cannot use a full URL in a 401 ErrorDocument directive --- ignoring!

Line 6 of my .htacess looks straight forward:

ErrorDocument 401 http://error.foo.bar/401.html

Why can't a full URL in a 401 ErrorDocument directive be used? Bug or Feature?

Best Answer

You can use only local URL-path in response to code 401. It is because

when you specify an ErrorDocument that points to a remote URL (ie. anything with a method such as http in front of it), Apache HTTP Server will send a redirect to the client to tell it where to find the document, even if the document ends up being on the same server. This has several implications, the most important being that the client will not receive the original error status code, but instead will receive a redirect status code. This in turn can confuse web robots and other clients which try to determine if a URL is valid using the status code. In addition, if you use a remote URL in an ErrorDocument 401, the client will not know to prompt the user for a password since it will not receive the 401 status code. Therefore, if you use an ErrorDocument 401 directive, then it must refer to a local document.

Related Topic