Hi NogDog,
thank you, but the task I was facing was a little different.
I had 3 areas of a website, one of which was to be protected in a htaccess-like way (for consistancy reason). There were no directories for the different areas, they were only simulated by rewrite rules, like
RewriteRule (area1|2nd_area|private)/([a-zA-Z0-9]*)$ /index.php?dir=$1&p=$2
Thus I could not make use of htaccess here, and used to have php do the user validation within that index.php script using $SERVER['PHP_AUTH_USER'] and $SERVER['PHP_AUTH_PW'].
What I ended up with is
- creating a directory "private" has normal password protection with htaccess
- adding a rewrite rule to this htaccess
(RewriteRule [a-zA-Z0-9]$ /index.php?dir=private&p=$0)
- taking the private area out of the general rewrite rule in the root directory
(RewriteRule (area1|2nd_area)/([a-zA-Z0-9])$ /index.php?dir=$1&p=$2)
This seems to work out quite well as the user authentication is processed prior to the rewriting at least on my server.
I am aware that this protection is somewhat weaker as anyone who is able to guess the real URL index.php?dir=private&p=xy would be able to skip the authentication alltogether. To reduce this risk, I have index.php at least validate the user name via $_SERVER['REMOTE_USER']. Still by no ways bulletproof, but sufficient for the security level these contents need.
Thanks again,
m