Using mod_rewrite to pass REMOTE_USER on to mod_proxy in Apache
This was wrecking my head horribly earlier because I kept hitting the limit imposed by LimitInternalRecursion
without realising why. It turns out that I was missing the following:
RewriteCond %{IS_SUBREQ} ^false$
That ensures that the rewriting to copy the value of the REMOTE_USER
environment variable is done once and once only. Here’s the full ruleset:
RequestHeader Unset X-Forwarded-User
RewriteEngine On
RewriteCond %{IS_SUBREQ} ^false$
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule .* - [E=RU:%1]
RequestHeader Set X-Forwarded-User %{RU}e env=RU
With luck, this’ll save somebody else from wasting their time like I ended up doing.