如何在我的Apache代理查询字符串的URL? [英] How can I proxy a query string URL in Apache?
问题描述
我想获得较旧的Apache(2.2.17)代理:
I'm trying to get an older Apache (2.2.17) to proxy:
http://foo.com/proxy/? URL = HTTP%3A%2F%2Fbar.com%2foo
到
我有:
的RewriteCond%{QUERY_STRING} ^ URL =(。*)$结果
重写规则^ /代理/%1吗? [P,L]
RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^/proxy/ %1? [P,L]
不幸的是,这会导致Apache的努力代理网址恩codeD值(对数输出):
Unfortunately, this results in Apache trying to proxy the URL-encoded value (log output) :
(3)将图案'^ /代理/'来的uri'/代理/'搜索
(4)的RewriteCond:(。*)输入='URL ='的http%3A%2F%2Fbar.com%2foo'模式='^ URL = $'=>匹配的结果
(2)重写'/代理/' - ?>''的http%3A%2F%2Fbar.com%2foo'搜索
(3)拆分URI =的http%3A%2F%2Fbar.com%2foo? - > URI ='的http%3A%2F%2Fbar.com%2foo',ARGS =结果
(2)强制代理吞吐量 http://foo.com/ 的http%3A%2F%2Fbar.com %2foo'结果
(1)反超与代理请求代理:HTTP://foo.com/'http%3A%2F%2Fbar.com%2foo[OK]搜索结果
(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]
因此,似乎存在两个问题。之一是,有在结果撇号,而另一个是结果不是URL德$ C $光盘。我认为原因Apache是prepending原始协议://主机是不会看到的结果作为一个网址
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.
推荐答案
如果你有机会获得虚拟主机/服务器配置(和它看起来像你这样做),你可以配置apache的内置重写映射到反转义为你的产品:
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]
这篇关于如何在我的Apache代理查询字符串的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!