Apache – Strip URL Param and Add as Custom HTTP Header on Redirect

apache-2.2http-headersredirect

Let's say my browser issues a request to http://localhost/accounts?memberUuid=<some uuid>

I'd like apache2 to pickup that request, add a custom HTTP header with the uuid in it, strip the uuid param from the URL, and redirect to http://localhost:9000/accounts with the new custom header.

I'm a total apache noob. I have only used it as a simple web server for serving html, css, and javascript files. So I don't even know where to begin, otherwise I'd post some things I've tried so far.

Is this possible with apache2 alone? Do I need some additional tools running to accomplish this? Thanks!

Edit

This makes it look like I should be able to add whatever headers I want to a request. Or am I misunderstanding this? How would I use this along with an incoming value on the URL to send the header I need?

Best Answer

This turned out to be possible by combining RewriteRule with Proxy

<VirtualHost *:80>
  RewriteEngine On
  RewriteCond %{QUERY_STRING} ^(.*)memberUuid=(.*)$
  RewriteRule ^/(.*)$ http://127.0.0.1:9000/$1 [E=memberUuid:%2,P]
  ProxyPreserveHost On
  ProxyPass /excluded !
  ProxyPass / http://127.0.0.1:9000/
  ProxyPassReverse / http://127.0.0.1:9000/

  Header add iv-user "%{memberUuid}e"
  RequestHeader set iv-user "%{memberUuid}e"
</VirtualHost>