Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom error page in Apache2 for 401

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

like image 226
Parris Varney Avatar asked Dec 02 '10 23:12

Parris Varney


People also ask

Where are Apache default error pages?

The location of Apache 2.4 standard error messages is inside the executable. You can easily find them if you peek inside the executable with some hex editor.

What is a 404 error Apache?

A 404 error page indicates that the page we are trying to access is not able to locate. It is also known as the File Not Found page. At Bobcares, we often get requests regarding Apache errors, as a part of our Server Management Services.

Is the error code that is sent by Apache as a response?

Apache error codes (401, 403, 404, 412, 500)


2 Answers

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>
like image 189
Sam Coles Avatar answered Sep 21 '22 00:09

Sam Coles


ErrorDocument takes in a absolute URL path instead of a file path. So it should be:

ErrorDocument 404 /error/error.html

Assuming under your document root is a /error/error.html file.

like image 23
Батырбек Бақытжанов Avatar answered Sep 24 '22 00:09

Батырбек Бақытжанов