Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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'
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
    
Hi. But there is no real directory /webdav. Do I still need to define it? –  Chris Mar 7 '13 at 21:43
    
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 8 '13 at 13:24
    
Thanks. That was it. Now it is working like a charm. –  Chris Mar 8 '13 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.