You are not logged in.
Situation: I have to serve up some webpages but I can't modify the content. The content needs to be protected with a username and password and for that I'm using apache mod_digest over http (it's an internal site).
For tracking purposes outside of my control, I need to add the %REMOTE_USER name to the URI and then ignore it.
For example:
Browse to test.com
Get prompted for username and password (this is working fine)
Login successfully as user guest
Redirected to: http://test.com/guest/
All of the following calls get the same rules: http://test.com/img1.jpg should be written as http://test.com/guest/img1.jpg
All of these user URIs should map to the same Location/DocumentRoot:
http://test.com/guest/img1.jpg -> /var/htdocs/img1.jpg
http://test.com/msalerno/img1.jpg -> /var/htdocs/img1.jpg
http://test.com/msalerno -> /var/htdocs/
http://test.com/guest -> /var/htdocs/
I'm still trying to get the configuration right. The only examples I can find do the inverse of what I need, they keep the URI the same but rewrite the directory location. I put the following rewrite rule in place, It does the most of what I need it to do, but at least it's a starting point. It's still rewriting the internal directory.
RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} ^[a-z].*
RewriteCond %{REQUEST_URI} !/%{LA-U:REMOTE_USER}/(.+)$
RewriteRule ^(.*)$ /%{REMOTE_USER}/%1 [R]
Any help would be greatly appreciated.
Thanks
Last edited by msalerno (2018-04-25 13:32:03)
Offline
Unfortunately, the rules I pasted above cause too many redirects. Still working on a solution.
Offline
Solution:
<Server>
AliasMatch "^/users/.*" "/usr/local/apache2/htdocs/"
..
<Directory "/usr/local/apache2/htdocs">
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/usr/local/apache2/Basic_pw"
Require valid-user
RewriteEngine on
RewriteCond %{REQUEST_URI} !/users/(.+)$
RewriteRule ^(.*)$ /users/%{REMOTE_USER}/$1 [R]
...
I was making it way too complicated
Offline
Glad to see you've found a solution, please mark the topic as such by prepending [SOLVED] or similar to the title in your first post.
Offline