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 managed to use apache to strip off a url param and stuff it in a header to be passed on to another server. See this question for reference.

Now I would like to add to this by getting the value for the header from a cookie if it's not present in the URL. Here's what I tried:

<VirtualHost *:80>
  RewriteEngine On

  RewriteCond %{QUERY_STRING} ^(.*)memberUuid=(.*)$
  RewriteRule ^/(.*)$$1 [CO=memberUuid:%2:localhost,E=memberUuid:%2,P]

  RewriteCond %{HTTP_COOKIE} memberUuid=(.*)
  RewriteRule ^/(.*)$$1 [E=memberUuid:%2,P]

  ProxyPreserveHost On
  ProxyPass /excluded !
  ProxyPass /
  ProxyPassReverse /

  Header add iv-user "%{memberUuid}e"
  RequestHeader set iv-user "%{memberUuid}e"

This still works if the memberUuid is in the URL, but it doesn't seem to work with the cookie. I have the memberUuid cookie in my browser, but if I leave the URL param off, the iv-user header has an empty value.

I also tried ([^;]+) for my regular expression, as recommended in this post.

I'm sure that my mistake has a lot to do with me being a complete apache idiot. I'm a complete noob and not embarrassed to say it. Enlighten me please!


I've updated my virtual host so that apache will set the memberUuid cookie in the user's browser if it comes from the query string. That way, I can be sure that the cookie is present on the next request (I was previously having the destination server do this).

share|improve this question
up vote 2 down vote accepted

This might not be the only issue (I've never done cookie matching in mod_rewrite before); but I think it's because your backreference for the RewriteRule is still %2. You only have one parenthesised match in the previous RewriteCond, so it expands to nothing. Try [E=memberUuid:%1,P]

share|improve this answer
Ok, that should have been a no-brainer. That's what I get for working late! – Samo Aug 5 '12 at 22:24

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.