Proxy puts trailing slash after params.

Oh, the strange things mod_rewrite does!

Proxy puts trailing slash after params.

Postby skeeter » Sat Jan 19, 2008 4:13 pm

I want everyone who requests www.somedomain.com/files/ to transparently access files served from another application/location.

Because the application I am using wants some indication as to who the user is, I cannot redirect and have the user id show-up in the address bar for obvious reasons.

This is a simple application that will take care of itself except that I do want to collect some information with the http request and keep that in a survey data log file hense the proxy.

So for every request to:

www.somedomain.com/files
www.somedomain.com/files/
www.somedomain.com/files/<anything>

I want to proxy to:

http://www.mydomain.tld/proxy/proxy.plx ... red&from='%{REMOTE_ADDR}'&agent='%{HTTP_USER_AGENT}'&referer='%{HTTP_REFERER}'

...where authorized-user-id will be manually edited into the .htaccess file and the rest as you would expect.

This seems to work fine on my Cobalt server... but not in the real world.

# file proxy
RewriteCond %{REQUEST_URI} ^/files$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/files/$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/files/.*$ [NC]
RewriteRule .* http://www.mydomain.tld/proxy/proxy.plx ... red&from='%{REMOTE_ADDR}'&agent='%{HTTP_USER_AGENT}'&referer='%{HTTP_REFERER}' [P,L]

The real world server tries to proxy but puts a / at the end of the line after the parameters thus confusing apache.

It would all work fine if I could just figure out why a slash is being put at the end of the URL.

Any ideas as to what I am doing wrong??

Thanks in advance!
Skeeter-
skeeter
 
Posts: 8
Joined: Sat Jan 19, 2008 3:49 pm

Postby richardk » Sat Jan 19, 2008 4:46 pm

Does the files directory exist one the server? Do you have any other mod_rewrite or redirects?

The real world server tries to proxy but puts a / at the end of the line after the parameters thus confusing apache.

How do you know? Does it output an error? Why does it confused Apache (you can have slashes in query string parameters so it shouldn't be a problem).

Also, you should only need
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^files(/.*)?$ http://www.mydomain.tld/proxy/ ... ='%{HTTP_REFERER}' [P,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby skeeter » Sat Jan 19, 2008 4:55 pm

Thanks for the fast reply...

The /files/ directory does happen to exist but not intended to... I just put it there with a simple index.html to help debug. I should delete it.

I do see the request on www.mydomain.tld where the request is absolutely perfect except for the trailing slash. There is an error (of sorts) in the apache error log ...

File does not exist: proxy:http://www.mydomain... ...&referer='http://www.slpatech.com/'/

I will quickly try your suggestion and get back to you asap.

Skeeter-
skeeter
 
Posts: 8
Joined: Sat Jan 19, 2008 3:49 pm

Postby skeeter » Sat Jan 19, 2008 5:04 pm

Okay:

I tried the recommendation and it took me to /files/...

I then renamed /files/ to /xfiles/ [jic] and it errors.

I realize that I am doing something out of the ordinary... but it seems like it is something that is acheivable and should work okay.

Thanks again...
Skeeter-
skeeter
 
Posts: 8
Joined: Sat Jan 19, 2008 3:49 pm

Postby richardk » Sat Jan 19, 2008 5:10 pm

Are you sure mod_proxy is enabled? Can you proxy to another URL? Try
Code: Select all
RewriteRule ^test$ http://example.com/ [P,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby skeeter » Sat Jan 19, 2008 5:28 pm

I did try a generic proxy like you recommended and it did not work... I tried a few variations/itterations... and nothing.

How do I turn mod_proxy on? I saw ProxyRequests On... but that returns a 500 error even with all the proxy stuff commented out.

Thanks!
Skeeter-
skeeter
 
Posts: 8
Joined: Sat Jan 19, 2008 3:49 pm

Postby skeeter » Sat Jan 19, 2008 6:03 pm

Okay. It is now...

Sorry for the confusion...

I tried the test recommendation you made earlier and it did not work with or without the /files/ directory... however...

I did try RewriteRule .* http://www.mydomain.tld/ [P,L] and it did proxy from the www.somedomain.com home page telling me that mod_proxy is working okay.

Thanks!!
Skeeter-
skeeter
 
Posts: 8
Joined: Sat Jan 19, 2008 3:49 pm

Postby skeeter » Sat Jan 19, 2008 7:07 pm

Oooooppppsssss..... sorry!

I goofed. One little fat-finger and all hell breaks loose!

I was able to www.mydomain.tld from www.somedomain.com/files/ okay...

But it did not like the whole URL from the example I orginally gave.

I get - request failed: erroneous characters after protocol string:

I will reconstruct the param list one at a time time see here it fails...

Trying to figure that out now... though I have to admit, I have been at this all day and I might give-up for the night soon. I am thinking I need to get a life... maybe do something... with a human instead of a machine.

Thanks for your help!
If you have any ideas, let me know...

Skeeter-
skeeter
 
Posts: 8
Joined: Sat Jan 19, 2008 3:49 pm

Postby skeeter » Sat Jan 19, 2008 7:40 pm

Okay.

I seems to fail on the referer and agent parameters... as I reconstructed the param list one at a time (I was sure where it was failing but I needed to know for sure) I got to agent and I get the error.

Here is an example of what apache see and fails on...

&agent='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; DigExt; Q312461; SV1; .NET CLR 1.1.4322)'

I tried ", \", %22, \%22, NE and a whole host of itterations- I have been around and around so much on this I am not looking at this clearly anymore.

Skeeter-
skeeter
 
Posts: 8
Joined: Sat Jan 19, 2008 3:49 pm

Postby richardk » Mon Jan 21, 2008 10:16 am

The problem is almost certainly the spaces (which is \%20 or +). If you have access to the httpd.conf file you can set up the escaping RewriteMap and do this, the RewriteMap
Code: Select all
RewriteMap urlEscape int:escape

Then in the mod_rewrite use
Code: Select all
${urlEscape:%{HTTP_USER_AGENT}}

and
Code: Select all
${urlEscape:%{HTTP_REFERER}}

instead of
Code: Select all
%{HTTP_USER_AGENT}

and
Code: Select all
%{HTTP_REFERER}

respectively.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 3 guests

cron