.htaccess & user/pass auth with custom 401 error message
Results 1 to 5 of 5

Thread: .htaccess & user/pass auth with custom 401 error message

  1. #1
    i like computers
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    632

    .htaccess & user/pass auth with custom 401 error message

    I have a setup w/ zend framework.

    I have a development site which I have protected with require valid-user.

    I want to setup a custom 401 ErrorDocument that tells myusers to goto the production site (if they stumble on dev site)

    When I add ErrorDocument 401 error/401.html to the .htaccess, I get the standard Authorization Required string plus:

    Code:
    Additionally, a 401 Authorization Required error was encountered while trying to use an ErrorDocument to handle the request.
    I don't know enough about Apache's rules to make a rule to allow that document to be viewed, any ideas?
    big.nerd

    Most Code Provided is UNTESTED (unless otherwise specified).
    ... nerds are real people too!

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Try something like...
    Code:
    <Files 401.html>
    Order allow,deny
    Allow from all
    </Files
    to make sure that Apache doesn't require authentication for it.

  3. #3
    i like computers
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    632
    bradgrafelman,

    Thanks for the suggestion however it did not seem to work for me.

    Here is what I have tried:

    Code:
    # Set Access Restrictions
    
    AuthName "Development Area" 
    AuthType Basic 
    AuthUserFile /path/to/.htpasswd 
    AuthGroupFile /dev/null 
    require valid-user
    ErrorDocument 401 /error/401.html
    
    <Files error/401.html>
    Order allow,deny
    Allow from all
    </Files>
    RewriteEngine On
    RewriteCond &#37;{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ /index.php [NC,L]
    I have also tried /error/401.html and 401.html only under the files definition.

    Thanks, I know there must be a way!
    big.nerd

    Most Code Provided is UNTESTED (unless otherwise specified).
    ... nerds are real people too!

  4. #4
    Un Re Member cretaceous's Avatar
    Join Date
    Sep 2004
    Location
    London UK
    Posts
    940
    ErrorDocument 401 /pagenotfound.php
    ErrorDocument 403 /pagenotfound.php

    should do it...

    edit:
    if it is in a directory called 'error' I bet its not finding the directory properly
    Last edited by cretaceous; 11-12-2009 at 06:34 PM.

  5. #5
    i like computers
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    632
    cretaceous,

    I tried leaving the document in the root as well, even though that is untidy with my structure and it didn't work.

    Thanks though!
    big.nerd

    Most Code Provided is UNTESTED (unless otherwise specified).
    ... nerds are real people too!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •