Forum Moderators: phranque
I've been completely flummoxed by this little bit of mod_rewrite that I've been trying to get working.
Basically, I have a site that is password-protected. When the user first requests a page, a username/password is required. Then, depending on the username required, the relevant subfolder in the site is pulled up. Quite similar to having multiple users almost, and having visitors redirected to their "home" directory.
I discovered the wonderful little
%{REMOTE_USER} variable, which is quite helpful. However, when trying to combine this with other logic, it doesn't really work. For example, this works:
RewriteRule (.*) %{REMOTE_USER} [L] %{REMOTE_USER with anything, an internal error occurs. So, something like RewriteRule (.*) /%{REMOTE_USER}/$1 [L] fails. Then I though I could do it the standard way, using variables. So, this is my next example:
RewriteCond %{REMOTE_USER} ^(.*)$
RewriteRule (.*) %1 [L]
%1 in the RewriteRule, it fails. So this doesn't work:
RewriteCond %{REMOTE_USER} ^(.*)$
RewriteRule (.*) /%1/$1 [L]
This really does have me flummoxed. If anyone can offer any suggestions as to what it could be, I'd really appreciate it.
*G
That's my best guess, since you did not define "doesn't work" or include any error log messages...
Unfortunately, there's no good solution that does require a specific subdirectory-name, an additional user-defined variable, or some other method to allow Apache to 'remember' that it has already applied this rewrite. Something like this might work:
RewriteCond $1 !^user_
RewriteRule (.*) /user_%{REMOTE_USER}/$1 [L]