Идея заключается в том, что люди просто переходят в / directory /
и вводят свое имя пользователя и пароль. Затем он перенаправит их в / directory / username /
и проверит соответствие каталога и имени пользователя, если они попытаются перейти в чужой каталог.
AuthType Basic
AuthName "Your Realm Name"
Order allow,deny
AuthUserFile .......
Require valid-user
RewriteEngine On
#If just to /directory then redirect to the per user area
RewriteRule ^$ /directory/%{REMOTE_USER} [R,L]
#WARNING: make sure usernames can't have slashes in them
#grab the directory from the URL from RewriteRule (it's called $1)
#use a REGEX backreference to see if $1 equals %{REMOTE_USER} with a slash in between for performance
RewriteCond $1/%{REMOTE_USER} !^([^/]+)/\1$
#If they don't match then give them a fail page
RewriteRule ^([^/]+) - [F]