Welcome to WebmasterWorld Guest from 34.204.191.31

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

apache is converting %3F to ?

apache is converting %3F to?

     
7:46 pm on Jun 6, 2008 (gmt 0)

New User

10+ Year Member

joined:June 6, 2008
posts: 1
votes: 0


We have apache proxying a mongrel cluster using mod_balancer. The URL hitting apache is something like:

[blah.com...]

Apache is handing this off to the mongrel cluster like:

[blah.com...]

however, I really want it to hand it off like:

[blah.com...] because the %3F is important and needs to be sent over.

Our current rewrite rules to the cluster are like:

# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://blah_cluster%{REQUEST_URI} [P,QSA,L]

I've tried to modify these rules to pass along the %3F but nothing worked. Any ideas?

3:52 pm on June 8, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


You are wishing for a behavior that violates the HTTP protocol concerning the allowed characters within each part of a URL and the query string attached to it. See RFC2396. Apache is enforcing the RFC by converting the %3f to "?" as it should. You may be able to override this using the [NE] flag on RewriteRule, but I've never tried it, as this would be sort of an "opposite" function to that described for it.

Another approach might be to use a RewriteCond to create back-references to THE_REQUEST for use in the RewriteRule. THE_REQUEST is the actual request header received from the client, and is not subject to any decoding or un-escaping as are REQUEST_URI and the URL-path examined by RewriteRule.

THE_REQUEST might look like this, for example:

GET /blah/monster_of_the_midway%3F HTTP/1.1

and might be handled with code like:


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]*)\ HTTP/
RewriteCond %{DOCUMENT_ROOT}/%1 !-f
RewriteRule ^/(.*)$ balancer://blah_cluste[b]r/%1[/b] [P,QSA,L]

There was a problem with the original code above, in that the 'exists' check was done on a path with two slashes in it, since REQUEST_URI includes the leading slash on the URL-path. I've tried to be careful with the leading-slash issue in my snippet here -- see the bolded area in the RewriteRule substitution.

Be aware that you're fighting Apache's various mod_dir fix-up routines here. Apache is going to "want to correct" your URI to "http://www.blah.com/blah/monster_of_the_midway/?" -- Note the slash preceding the "?". As a result, my code snippet may not work, or it may only offer a partial solution and need to be modified.

Jim