1

I'm trying to get an older Apache (2.2.17) to proxy:

http://foo.com/proxy/?url=http%3A%2F%2Fbar.com%2foo

to:

http://bar.com/foo

I have:

RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^/proxy/ %1? [P,L]

Unfortunately, this results in Apache trying to proxy the URL-encoded value (log output) :

(3) applying pattern '^/proxy/' to uri '/proxy/'
(4) RewriteCond: input='url='http%3A%2F%2Fbar.com%2foo'' pattern='^url=(.*)$' => matched
(2) rewrite '/proxy/' -> ''http%3A%2F%2Fbar.com%2foo'?'
(3) split uri='http%3A%2F%2Fbar.com%2foo'? -> uri='http%3A%2F%2Fbar.com%2foo', args=
(2) forcing proxy-throughput with http://foo.com/'http%3A%2F%2Fbar.com%2foo'
(1) go-ahead with proxy request proxy:http://foo.com/'http%3A%2F%2Fbar.com%2foo' [OK]

So, it appears there are two problems. One is that there are apostrophes in the result and the other is that the result is not URL decoded. I assume the reason Apache is prepending the original protocol://host is that it doesn't see the result as an URL.

1 Answer 1

3

If you have access to vhost/server config (and it looks like you do), you can configure one of apache's built in rewrite maps to unescape for you:

RewriteMap unescape int:unescape

Then you can use the map in your rules:

RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^/proxy/ ${unescape:%1}? [P,L]
Sign up to request clarification or add additional context in comments.

2 Comments

This fixed the URL-decoding problem. I'm now getting: foo.com/'http://bar.com/foo' How do I get rid of the apostrophes and get it to proxy the real URL?
@JayVachhani that shouldn't be there at all, this works for me in my apache install. Unless there's ' around the url in the query string, I guess you can get rid of those optionally by changing the regex to: ^url='?(.*?)'?$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.