Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite acting strangely

         

ffoeg

5:55 am on Nov 26, 2008 (gmt 0)

10+ Year Member



Hey all.

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]

However, as soon as I try to combine the
%{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]

Again, it works like this; but as soon as I combine the
%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

jdMorgan

12:54 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is probably not the use of the REMOTE_USER variable in itself, but rather that once you actually do the rewrite, there is nothing to stop the rule being re-applied again and again, resulting in an 'infinite' internal rewrite loop.

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]

Jim