mod_rewrite not working due to mod_auth?

352 Views Asked by At

I must have discovered a bug in Apache! Because I have the wierdest issue with my webhost. I cannot access a folder named admin. It works in one virtualhost but not the other. (Same hosting account)

/.htaccess

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /

  # No logic for resolved paths
  RewriteCond %{REQUEST_FILENAME} -d [OR]
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -l
  RewriteRule ^ - [L]

  RewriteRule .* index.php [L]
</IfModule>

/admin/.htaccess:

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/user/domains/mydomain.com/public_html/admin/.htpasswd
Require valid-user

Resolving http://www.mydomain.com/admin/index.php I get 404 not found. If I remove the admin/.htaccess file the page resolves. What's up with that?

2

There are 2 best solutions below

0
On BEST ANSWER

The problem derives from the ErrorDocument setting. Adding the following line to admin/.htaccess solves the problem

ErrorDocument 401 "Access Denied"

2
On

See my Tips for debugging .htaccess rewrite rules. Unless oyu've overridden the defaults with on of the RewriteOptions Inherit* directives, then because the /admin/.htaccess exists then the parent one won't be executed. Either add

RewriteOptions Inherit

to this file or simply repeat the rewrites that you need in the admin access file.