The location of the error document is relative to the document root. For example, in my case I have:
Code:
ErrorDocument 404 /error_404.bot
and my docroot is /var/www/htdocs so I place "error_404.bot" in "/var/www/htdocs/".
In your case I think you want:
Code:
ErrorDocument 401 /somedomain/authfail.php
As for namebased virtual hosts, AFAIK you can just place the "ErrorDocument" directive inside each sites VirtualHost block ie:
Code:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
ErrorDocument 401 /authfail.php
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org
ErrorDocument 401 /authfail.php
# Other directives here
</VirtualHost>
And for example1.org /www/example1/authfail.php will be served and for example2.org /www/example2/authfail.php will be served.