Score:0

Apache VirtualHost - per user ProxyPass

sz flag
b0d

I'm trying to configure Apache to redirect users to different paths based on their authentication credentials (using htpasswd). I've managed to set up ProxyPass, which enables the redirection of the request to a custom path, however all of the users now get redirected to the same path. This happens because of using the same <Location /> directive for all of the users. When I try with <Location /user123>, <Location /user456>,.. it works like intended, but I'd like for Apache to forward the / location to appropriate paths based on provided credentials. Is this possible?

in flag
Could be possible by using rewriterule instead of ProxyPass, it supports variables.
Score:0
br flag

Looking at the question more closely, since you are using the apache instance to authenticate using htpasswd file. I believe you can reference the REMOTE_USER variable.

I believe you can use something like the following in your apache config.

ProxyPass / http://localhost:8080/%{REMOTE_USER}/
ProxyPassReverse / http://localhost:8080/%{REMOTE_USER}/
diya avatar
la flag
And if ProxyPass doesn't support variable expansion ; use the RewriteRule from your other answer, but with a [`P|proxy`](https://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_p) flag rather than the R|redirect .
schezel2000 avatar
br flag
Cool, I was not aware of the P flag.
Score:0
br flag

Looking at apache with mod_rewrite. I believe you could do something like the following. The remote_user variable is available to apache in the config. I believe you can do something like the following.

RewriteCond "%{REMOTE_USER}"  "!^$"
RewriteRule "^/(.*)"  "/$1/%{REMOTE_USER}" [R]

The condition says if the remote user exists with a value that is not an empty string then rewrite urls with a remote url. You also could do a redirectmatch as well.

RedirectMatch "^/(.*)" "/$1/%{REMOTE_USER}"

Here are my references. This shows the variables available to mod_rewrite https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

This show examples of mod_rewrite in action https://httpd.apache.org/docs/2.4/rewrite/remapping.html

in flag
That's pretty much what I imagined. But the OP want's to proxy, not redirect.
schezel2000 avatar
br flag
Really not sure about the proxy. I would put these rewrite rules on whatever is on the receiving end of the proxy.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.