Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess rewrite and auth conflict

I have 2 directories each with a .htaccess file:

html/.htaccess - There is a rewrite in this file to send almost everything to url.php

RewriteCond %{REQUEST_URI} !(exported/?|\.(php|gif|jpe?g|png|css|js|pdf|doc|xml|ico))$
RewriteRule (.*)$ /url.php [L]

and html/exported/.htaccess

AuthType Basic
AuthName "exported"
AuthUserFile "/home/siteuser/.htpasswd"
require valid-user

If I remove html/exported/.htaccess the rewriting works fine and the exported directory can be access. If I remove html/.htaccess the authentication works fine.

However when I have both .htaccess files exported/ is being rewritten to /url.php. Any ideas how I can prevent it?


2 Answers

As far as I understand, the '404' error occurs because Apache cannot find the '401 Authentication Needed' page. So I simply solved it by creating html/401.html, and adding

ErrorDocument 401 /401.html

to my html/.htaccess

Hint was taken from http://drupal.org/node/52465#comment-106353

like image 111
Oren_H Avatar answered Nov 27 '25 00:11

Oren_H


I think you may have meant this for your regex:

RewriteCond %{REQUEST_URI} !(^exported/?|\.(php|gif|jpe?g|png|css|js|pdf|doc|xml|ico)$)
RewriteRule (.*)$ /url.php [L]

Does html/exported/exported/ work in your current setup by any chance?

like image 27
Paul McMillan Avatar answered Nov 27 '25 00:11

Paul McMillan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!