I have password-protected the root folder of my website while i do maintenance, but I want to display a custom 401 error page to let people know the site is under construction. Unfortunately, my web host doesn't allow me write access to anything outside the root folder of my website, so this custom error page must by stored in the root folder or one of its subfolders. Instead of my custom error page I get the Apache default error page and it also says "Additionally, a 401 Authorization Required error was encountered while trying to use an ErrorDocument to handle the request."

I searched for ways to make a subfolder of a protected directory public, and all I could find was to use the "Satisfy any" directive, but this doesn't work for me. It doesn't work on a file-only basis either, as with the .htaccess file below.

#Authorization Restriction
AuthType Basic
AuthName "Access to root"
AuthUserFile *********************************
Require user ***********

Order Allow,Deny

Satisfy any

#Error Documents
ErrorDocument 401 Error-401.html

#Allow access to error documents
<Files Error-*,html>
Order Deny,Allow
Allow from all
Satisfy any

I can only use .htaccess files; I don't have access to httpd.conf


It's working for me. But you have a typo in <Files Error-*,html> instead of the comma should be dot: <Files Error-*.html>

On my localhost it works even without Files Directive. But on production server I had to use Satisfy any as you suggest.

You can place your custom 401 error directly into ErrorDocument:

ErrorDocument 401 "<html>...</html>"

Or you can envelope your Auth rules with <FilesMatch> and only negate the 401.html file:

<FilesMatch "^(?!401\.html$).+">
AuthType Basic
AuthName "Awe!"
AuthUserFile /full/path/to/.htpasswd
require user Lord

ErrorDocument 401 /401.html

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.