Custom error page in Apache2 for 401

Parris Varney picture Parris Varney · Dec 3, 2010 · Viewed 22.8k times · Source

Here's the relevant part of the .htaccess file:

AuthUserFile  /var/www/mywebsite/.htpasswd
AuthGroupFile /dev/null
AuthName  protected
AuthType Basic
Require valid-user

ErrorDocument 400 /var/www/errors/index.html
ErrorDocument 401 /var/www/errors/index.html
ErrorDocument 403 /var/www/errors/index.html
ErrorDocument 404 /var/www/errors/index.html
ErrorDocument 500 /var/www/errors/index.html

Docuement root is set to /var/www/mywebsite/web, it's on of many vhosts. I can navigate to the index.html page.

All I'm seeing is the generic Apache 401 page, any thoughts.

EDIT: This is the error message in my browser:

Authorization Required

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Additionally, a 401 Authorization Required error was encountered while trying to use an ErrorDocument to handle the request. Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny8 with Suhosin-Patch Server at www.dirbe.com Port 80

Answer

Sam Coles picture Sam Coles · Dec 3, 2010

Make sure that /var/www/errors is readable by the apache user and include this in your apache configuration:

<Directory /var/www/errors>
  Order allow,deny
  Allow from all
</Directory>