Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am currently trying to use mod_proxy to make search requests on another server. The remote server requests must be structured as follows:

In an effort to obfuscate my access key, I was hoping to contain the authentication within my vhost definitions. Since the key must be passed as a query string value, I thought it would be as simple as:

ProxyPass /lookup/t/

Where my URLs would look like


I quickly discovered that ProxyPass preforms mandatory character escapes on the target URL which rendered my URL unusable. I found lots of people who had similar issues, primarily with previously encoded characters, and that URL encoding with ProxyPass was unavoidable.

I found a few suggestions that I should use mod_rewrite to assemble the proxy request for me, but I wasn't sure how to do so. I ended up with rules in my vhost definition that look something like:

RewriteEngine On
RewriteCond     %{REQUEST_URI}      !^/lookup/t/
RewriteRule ^/lookup/t/$$1

I don't have a lot of experience with mod_rewrite, and my regex skills aren't great, so I'm hoping someone can explain how I would rewrite my URL and how to funnel it through mod_proxy as needed. Am I correct in thinking I need to use rewrite to assemble the query string like so:


and then use mod proxy to go from


share|improve this question
up vote 2 down vote accepted

My suspicions turned out to be correct. I had to modify the query string with mod_rewrite and then proxy it to my destination. In the end:

  1. I enabled mod_rewrite and mod_ssl
  2. I added an SSLProxyEngine directive to my vhost definition:
        SSLProxyEngine On
  3. I turned on rewrite and added a rule in my vhost def. I also turned on logging for debugging. I learned that I wouldn't be able to rewrite a request for the directory so I had to point to a script. I also had to use the QSA and P options:
        RewriteEngine On
        RewriteRule ^/lookup.php /lookup?key=MYKEY [QSA,P]

  4. I set up my proxy rules. Since the query string is constructed, simple proxying rules apply:
        ProxyPass /lookup
        ProxyPassReverse /lookup

  5. Don't forget to restart apache! (I did)

  6. I now connect to http://localhost/lookup.php?term=SEACRHTERM
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.