I would like to redirect to a certain folder based on the REMOTE_USER
value, so:
http://example.com/files
would redirect to:
/data/files/charlie/uploads
if the REMOTE_USER
value was 'charlie'.
I've tried many things, including this:
RewriteCond %{LA-U:REMOTE_USER} !^$
RewriteRule ^/files/(.*)$ /data/files/%{REMOTE_USER}/uploads/$1 [PT]
but nothing works. I get infinite loops and 404s.
I looked at <If>
but it seems REMOTE_USER
is not available during <If>
evaluation.
[EDIT:]
Current attempt, which results in a redirect loop for http://example.com/files/
looks like this:
# if REMOTE_USER is not empty string
RewriteCond %{LA-U:REMOTE_USER} !^$
# eg /files/foo -> /data/dev/uploads/charlie/foo
RewriteRule ^/files/(.*)$ /data/dev/uploads/%{LA-U:REMOTE_USER}/$1 [PT,L]
#...
<Directory /data/dev/uploads>
AllowOverride all
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd_dev
Require valid-user
</Directory>
Entire conf file:
<VirtualHost *:80>
ServerName example.com
ServerAdmin admin@example.com
DocumentRoot /usr/local/www/example.com/public_html
ErrorLog /usr/local/www/example.com/logs/error.log
CustomLog /usr/local/www/example.com/logs/access.log combined
ErrorLogFormat "%{c}t %M"
Header set Access-Control-Allow-Origin "*"
Header set Origin "http://example.com"
Header set Accept "Authorization"
ExpiresActive on
<FilesMatch "\.(html|htm|js|css|ico)$">
# Header set Cache-Control "max-age=31536000"
Header set Cache-Control "must-revalidate"
# ExpiresDefault "access plus 4 hours"
</FilesMatch>
WSGIScriptAlias /api /usr/local/www/example.com/server/server.py
WSGIPassAuthorization On
WSGIDaemonProcess example.com threads=15 python-path=/usr/local/www/example.com/server
WSGIProcessGroup example.com
Alias /files /data/dev/uploads
Alias /files/ /data/dev/uploads/
RewriteEngine On
# if REMOTE_USER is not empty string
RewriteCond %{LA-U:REMOTE_USER} !^$
# eg /files/foo -> /data/dev/uploads/charlie/foo
RewriteRule ^/files/(.*)$ /data/dev/uploads/%{LA-U:REMOTE_USER}/$1 [PT,L]
RewriteRule ^/play/(.*)$ /api/play/$1 [PT]
RewriteRule ^/screen/(.*)$ /api/screen/$1 [PT]
RewriteRule ^/static/(.*)$ /static/$1 [L]
RewriteRule ^/(list|edit|help|view).*$ /index.html [L]
<Directory /usr/local/www/example.com/public_html>
Require all granted
</Directory>
<Directory /usr/local/www/example.com/server>
Require all granted
</Directory>
<Directory /data/dev/uploads>
AllowOverride all
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd_dev
Require valid-user
</Directory>
</VirtualHost>
OK, this almost works:
RewriteRule ^/files$ /files/%{LA-U:REMOTE_USER} [PT,L]
Alias /files /data/dev/uploads
<Directory /usr/local/www/example.com/public_html>
Require all granted
</Directory>
<Directory /usr/local/www/example.com/server>
Require all granted
</Directory>
<Directory /data/dev/uploads>
Options +Indexes
AllowOverride all
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd_dev
Require valid-user
</Directory>
This seems to work:
RewriteCond %{LA-U:REMOTE_USER} !^$
RewriteRule ^/files/?$ /files/%{LA-U:REMOTE_USER} [PT,L]
Alias /files /data/dev/uploads
<Directory /data/dev/uploads>
AllowOverride all
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd_dev
Require valid-user
</Directory>
[PT] is to allow the Alias to pick up the redirection, although I'm not sure that's how it works...