2

I am trying to rewrite an url according to the authenticated user. But REMOTE_USER is always empty. Authentication works.

I am quite puzzled here... am I missing something?

RewriteEngine On
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 3

<Directory /home/storage>
        Order Allow,Deny
        Allow from all
        Dav On
        Options Indexes
        AllowOverride None

        AuthName "Webdav: insert your username and password"
        AuthType Basic
        AuthBasicProvider ldap
        AuthLDAPBindDN cn=adsyncldapagent,ou=Service,ou=AdminUsers,ou=ITS,dc=xx,dc=xx
        AuthLDAPBindPassword xxxx
        AuthzLDAPAuthoritative On
        AuthLDAPURL "ldap://xxxx/ou=Staff,ou=AUM,dc=xx,dc=xx?sAMAccountName?sub"

        <LimitExcept GET POST>
          Require valid-user
        </LimitExcept>
</Directory>

RewriteCond %{REQUEST_URI} ^/webdav
RewriteRule .   /home/storage/%{LA-U:REMOTE_USER}p

This is the rewrite log:

::1 - - [07/Mar/2013:20:26:17 +0100] [localhost/sid#7faeae695fe8][rid#7faeae766368/subreq] (2) init rewrite engine with requested uri /webdav
::1 - - [07/Mar/2013:20:26:17 +0100] [localhost/sid#7faeae695fe8][rid#7faeae766368/subreq] (3) applying pattern '.' to uri '/webdav'
::1 - - [07/Mar/2013:20:26:17 +0100] [localhost/sid#7faeae695fe8][rid#7faeae766368/subreq] (2) rewrite '/webdav' -> '/home/storage/p'
Chris
  • 607
  • 1
  • 7
  • 18

1 Answers1

4

You don't have any authentication configured for /webdav, so at the time this RewriteRule is triggered there is no REMOTE_USER. You need to have /webdav protected by the same authentication configuration that is protecting /home/storage.

Something like this:

<Directory /home/storage>
        AuthName "WebDAV"
        AuthType Basic
        AuthBasicProvider ldap
        AuthzLDAPAuthoritative On
        AuthLDAPURL "ldap://xxxx/ou=Staff,ou=AUM,dc=xx,dc=xx?sAMAccountName?sub"
</Directory>

<Location /webdav/>
        AuthName "WebDAV"
        AuthType Basic
        AuthBasicProvider ldap
        AuthzLDAPAuthoritative On
        AuthLDAPURL "ldap://xxxx/ou=Staff,ou=AUM,dc=xx,dc=xx?sAMAccountName?sub"
</Location>

RewriteRule ^/webdav/(.*) /var/www/webdav/%{LA-U:REMOTE_USER}/$1
larsks
  • 43,623
  • 14
  • 121
  • 180
  • Hi. But there is no real directory /webdav. Do I still need to define it? – Chris Mar 07 '13 at 21:43
  • 1
    If you don't define it somehow, the authentication will not be triggered, so that would be a **yes**. Since it's not a directory, you should use Location instead of Directory. – Jenny D Mar 08 '13 at 13:24