Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 ^/(.*)$ http://127.0.0.1:9000/$1 [CO=memberUuid:%2:localhost,E=memberUuid:%2,P]

  RewriteCond %{HTTP_COOKIE} 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>

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!

Edit

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.