Apache ProxyPass: pass requested URL as GET parameter to destination URL
13,629
You should be using the ProxyPassMatch
directive, if you want to use a regex, BUT as noted in the ProxyPass
directive documentation
url is a partial URL for the remote server and cannot include a query string.
As a result, you are going to have to use a RewriteRule
directive and set the [P]
flag to cause the request to be handled as a proxy request by mod_proxy
.
Although this probably needs some tweaking, a starting point might be:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/foo
RewriteRule ^(.*)$ /foo?url=$1 [P]
ProxyPass /foo http://example.com/
ProxyPassReverse /foo http://example.com/
Related videos on Youtube
Author by
Crylvarrey
Updated on September 18, 2022Comments
-
Crylvarrey over 1 year
Hi I'm trying to set ProxyPass to pass requested URL as GET parameter to destination URL, but I can't figure out how to write it in the config file.
I tried something like this:
ProxyPass ^(.*)$ http://example.com/?url=$1 ProxyPassReverse ^(.*)$ http://example.com/?url=$1
but it doesn't work. Can you help me please? Thanks!
-
Colt about 8 yearsFor clarity, even if you were using
ProxyPassMatch
, you do understand that^(.*)$
matches only the part of the URL that follows the "domain"? For example, if the URL for the request ishttp://proxy.com/foo/bar/file.ext
the match (i.e., the $1) will befoo/bar/file.ext
, without thehttp://proxy.com/
. Also, any query string followingfile.ext
will be automatically appended after the$1
, but as noted in answer below you cannot in aProxyMatch
specify a query string as part of the target url
-