Forum Moderators: phranque
I want to redirect any requests for /protected/public to /public. I put the rewrite rules in the .htaccess file that is located in /protected, above the Limit GET container (.htaccess file contents pasted below). What I expected it to do was to redirect requests for /protected/public if it matched, then if it was any other request, prompt for username/password. Instead it prompts for username and password first.
I tried putting 'satisfy any' in the Limit container, but that made /protected no longer password protected!
Is there a way around this?
.htaccess contents (changed to protect the innocent):
RewriteEngine On
RewriteRule ^public/(.*) /public/$1 [R=301,L]
<Limit GET>
AuthName "Admin"
AuthType basic
AuthUserFile /path/to/.htpasswd
require user admin
satisfy any
</Limit>
Therefore, the order of directives for different modules in your .htaccess file makes no difference to processing order. In this case, and in all properly-configured servers, mod_auth will run before anything else that could be used to modify server operation. Otherwise, you'd be hacker-bait.
Also, I hope you're aware that <Limit GET> only applies to GET requests; Your directory is completely open to anyone who wants to POST to or DELETE from it...
You can use SetEnvIf to pass info about requested URLs into mod_access to help with this problem. Something like:
RewriteEngine on
RewriteRule ^public/(.*) /public/$1 [R=301,L]
#
SetEnvIf Request-URI ^/protected/public/ allowredir
Order Allow,Deny
#
<Limit GET>
AuthName "Admin"
AuthType basic
AuthUserFile /path/to/.htpasswd
Require user admin
Satisfy any
Allow from allowredir
</Limit>
#
<LimitExcept GET>
Deny from all
</LimitExcept>
Jim
Also, I hope you're aware that <Limit GET> only applies to GET requests; Your directory is completely open to anyone who wants to POST to or DELETE from it...
Good tip, I'll keep that in mind!
I tried to do what you posted, but I couldn't get it to work. I ended up resorting to doing this in the VirtualHost container for the web site:
Alias /protected/public /path/to/public
And all is good now!
Thanks for your help...