You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Bhavin Modi <mo...@gmail.com> on 2005/10/01 01:01:29 UTC

Re: [users@httpd] How to use mod_rewrite with %{REMOTE_USER}

On 9/29/05, Joshua Slive <js...@gmail.com> wrote:
>
> On 9/29/05, Bhavin Modi <mo...@gmail.com> wrote:
> > RewriteRule ^/users/$ /users/%{REMOTE_USER} [R]
>
> > The %{REMOTE_USER} returns a value like
> > "uid=testuser,ou=people,dc=domain,dc=com", so I need to
> > filter "testuser" from this string.
> >
> > Is there any other way to do what I am trying to do ?
>
> RewriteCond %{REMOTE_USER} uid=([^,]+),
> RewriteRule ^/users/$ /users/%1

  This did not work. I also tried an [R] at the end.
I wrote an index.php file in /users/ to print the username passed
<?php
 print $_SERVER['PHP_AUTH_USER'];
 ?>
 This output "testuser" as output which means the regex in the RewriteCond
does work, but why does it not redirect to /users/testuser/. If I put the
same index.php file in /users/testuser/ and try to access the URL manually
it outputs "uid=testuser,ou=people,ou=domain,ou=com" which is the actual
%{REMOTE_USER} value. I also tried
 RewriteEngine On
RewriteRule ^/users/$ /users/testuser/ [R]
 without the RewriteCond, but it didnt redirect me. Am I doing something
wrong ?
 The other method I think I could restrict access is by matching the
<username> from /users/<username>/file-or-dir with uid value from
%{REMOTE_USER} and forbid access if it does match.
 Thanks,
Bhavin.