Forum Moderators: phranque

Message Too Old, No Replies

How to use Rewrite to add REMOTE_USER in querystring

Help with rewrite syntax

         

oldtimer1234

3:26 pm on Jun 14, 2005 (gmt 0)

10+ Year Member



I am trying to add the REMOTE_USER from the Header as a querystring parameter before proxying to next webserver. I have a module that authenticates the user, and I can see the variable in my destination test webserver as well as in a ethereal trace.
Authentication locally works fine.

Apache 2.0.52 on Windows

RewriteEngine on
RewriteLog c:\temp\rewrite.log
RewriteLogLevel 9
RewriteCond %{LA-U:REMOTE_USER} (.*)
RewriteRule ^/test.asp(.*) [somehost.com:81...] [P]

It works fine for other variables such as REMOTE_ADDR, REMOTE_HOST and HTTP:HOST but not for REMOTE_USER
I know that REMOTE_HOST is not set in the first phase but using LA-U should help?

The reason for doing this is that I have an old embedded webserver (not the above asp server) that is not capable of reading header variables, only querystrings

Help appreciated

oldtimer1234

3:27 pm on Jun 14, 2005 (gmt 0)

10+ Year Member



Typo

should of course be
I know that REMOTE_USER is not set in the first phase but using LA-U should help?

jdMorgan

12:45 am on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't comment on your proxy setup, except to say that your basic code is OK. You should not have to use LA-U in this case, because mod_auth runs before mod_rewrite (on a normally-configured server). If the user is authenticated, then REMOTE_USER will be provided by the client browser on every request.

The reason you may have problems with REMOTE_HOST is that the remote hostname must be acquired by your server by doing a reverse-DNS lookup on the REMOTE_ADDR of the incoming client request. Since your Web server must issue a request to your DNS server and wait for a respone, this information is not available until late in the API processing.

There should be no problem accessing REMOTE_USER and putting that info into a query string. I would expect your code to work. Maybe I don't understand your problem, though.

Jim

oldtimer1234

5:45 am on Jun 15, 2005 (gmt 0)

10+ Year Member



OK, nice to hear that it should work.
Just to make it clear:
I just want to add the value of REMOTE_USER to a querystring variable before proxying the request.
I know that REMOTE_USER is set as I can see that in the actual web browser request using ethereal

oldtimer1234

6:32 am on Jul 12, 2005 (gmt 0)

10+ Year Member



I do not why but this finally seems to work.

RewriteEngine on
RewriteLog c:\temp\rewrite.log
RewriteLogLevel 9
RewriteCond %{LA-U:REMOTE_USER} (.*)
RewriteRule ^/test.asp(.*) [somehost.com:81...] [QSA,P,L]

Using LA-U:REMOTE_USER instead of %1
I do not really care why, this works for me, just info to close this one.

jdMorgan

3:04 pm on Jul 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad to hear you got it working! Now that it works, be sure to turn that RewriteLogLevel down, or delete the logging directives entirely. Otherwise, all that logging is going to slow you down.

Jim